I have an index.php with the following content:
include_once('includes/auth.php');
include_once('classes/class.DatabaseQuery.php');
include_once('classes/class.Project.php');
include_once('classes/class.User.php');
$project = new Project();
$user = new User();
// HTML, HEAD, BODY
$usergroup = $user->getUserGroup($_SESSION['user']);
// ...
So I include all needed classes in my index.php. I also create an instance of the classes in this file. Then I have my class files (e.g. class.Project):
class Project {
private $db;
private $evaluation;
public function __construct($id=null){
$this->setPreferences();
}
private function setPreferences() {
$this->db = new DatabaseQuery();
$this->evaluation = new Evaluation();
}
public function getSomething(){
if($this->evaluation->checkSomething(1)){
echo "test";
}
}
// ...
}
In these files I declare my other classes as private variables. Than I access the methods of the other classes.
Are there any problems with the inclusion and the use of private variables with other classes?
Now I have a strange problem. If I write a value into $_SESSION['user'] my private variable user is overwritten. The session values are already filled before I write something in my session. Here is my login.php:
include_once('classes/class.User.php');
session_start();
$username = $_POST['username'];
$password = $_POST['password'];
$user = new User();
if ($user->checkLoginData($username, $password)) {
$_SESSION['userID'] = $user->getUserIDForName($username);
// it is an object
var_dump($user);
$_SESSION['user'] = $username;
// it is a string
var_dump($user);
// ...
}
How can $_SESSION['user']=$username change the content of the local variable $user? Perhaps you have some ideas what I’m doing wrong.
Solution:
Now I followed the advice from here, where
register_globalsshould be turned of. E.g. withhtaccess:php_value register_globals 0Seems to work.