Page 1 of 1

sessions and OOP

Posted: Wed Nov 09, 2005 10:39 pm
by Sequalit
When creating a OO project that holds members and stuff (like a weblog), when should i deal with the sessions?

Should I make a whole new class dealing with my sessions or should I store my session data in my member class (dealing with login and logout functions)?"????

Posted: Thu Nov 10, 2005 5:16 am
by feyd
session's are their own class, because they can store any information, not just user information. There's also being able to store sessions in various places too, such as in the database versus in the file system..

Posted: Thu Nov 10, 2005 5:18 am
by Jenk
Another method would be to store your member information in the session, or to session_register it.

Posted: Fri Nov 11, 2005 12:20 am
by Sequalit
Aye, well I was programming my member class and come across a problem... how should I store my sessions... or whens hould I impliment my sessions...

I got this far then stopped confused as to what would be a good idea...

Code: Select all

class Member extends core{
	session_start();
	$_SESSION['auth'];
	$_SESSION['id'];
	$_SESSION['restrictions'];
	
	var $dbid;
	var $dbusername;
	var $dbpassword;
	var $dbrestrict;
	
	function login($username,$password){
		$this->query("SELECT * FROM godschildren WHERE username='$username'");
		if($this->getRows() == 0){
			return 0;
		}
		$this->Assoc();
		$this->setVars($this->getData());
		if($this->dbpassword == $password){
			$_SESSION['auth'] = 1;
			$_SESSION['restrictions'] = $this->dbrestrict;
			$_SESSION['id'] = $this->dbid;
			return 1;
		}
	}
	function logout(){
		$this->dbid = "";
		$this->dbusername = "";
		$this->dbpassword = "";
		$this->dbrestrict = "";
		$_SESSION['auth'] = 0;
		$_SESSION['restrictions'] = "";
		$_SESSION['id'] = "";
	}
	function setVars($data){
		$this->dbid = $data['id'];
		$this->dbusername = $data['username'];
		$this->dbpassword = $data['password'];
		$this->dbrestrict = $data['restrictions'];
	}
	function isLoggedIn(){
		if($_SESSION['auth'] == 1){
			return 1;
		}else{return 0;}
	}
}
instead should i just make a seperate session class that deals with the session data?