Answer the question
In order to leave comments, you need to log in
How to secure class data?
Hello. There is a class (because theory is needed) User, News, ... How do you work with the entered data?
<?php
class User {
private $name;
function setName($name){
$this->name = $name;
}
function getName(){
return $this->name;
}
}
$user = new User();
$user->setName('<b>%Name+%</b>');
echo $user->getName();
// как быть при записи в БД уже готового класса
// где, что проверит удобнее?
// или каждое значение потом экранировать,
$DB->query("INSERT ... $user->getName()");
Answer the question
In order to leave comments, you need to log in
Look at ready-made implementations of the active record pattern and ORM
Usually there are separate classes for checking the types of variables, they are either taken out into helpers, or shoved into the logic of the model (which, IMHO, is very clumsy). On escaping - if your string assumes the presence of special characters, which is normal in principle, the use of a prepared statement saves the situation for anyone.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question