I am working on the login page and have this at the top:
Code: Select all
<?php
//other includes and objects off topic are excluded in this post.
session_start();
require "constants.php";
require constant('CLASSES_INCLUDE_PATH') . "/class.db.php";
require "appclasses/class.user.php";
//Big problem:
$objDB = new DB();
if (!isset($_SESSION['objUser'])){
$_SESSION['objUser'] = new user($objDB);
}
//:melborp giB
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// here goes the rest. blablablablabla...
?>I will use sessions and I will place objUser in the session. I guess that could be done exactly the way I did above.
The user object initialisation takes a parameter $objDB which is refered to like this in the user class initialisation:
Code: Select all
<?php
class user{
var $objDB;
var $intLoggedInID;
function user(&$objDB){
$this->objDB = & $objDB; // Here, the $objDB has to be initialised before.
}
function attemptLogin($strUsername, $strPassword){
$arrUser = $this->objDB->queryGetFirstRow('SELECT ID FROM Users where strUsername=''' . $strUsername . ''' and strPasswordHash=PASSWORD(''' . $strPassword . ''') ');
if ($arrUser){
$this->intLoggedInID = $arrUser['ID'];
}else{
return false;
}
}
}
?>This gets me wondering:
1: Should I store the session data without storing the object?
2: Should I also have the $objDB stored in the session?
If I go the "1" way, I will lose the structure I believe I am designing right now. I don't want that.
If I go the "2" way, memory won't be used effectively.
Which way would an experienced PHP-OOP-developer go?
Am I completely off track?