mem0ri Posted March 8, 2007 Share Posted March 8, 2007 Just as a start, yes, I have searched these forums through previous session topics just to make sure I wasn't creating needless spam. Situation: All of my user-data is maintained by a PHP Class function called 'initialize: class initialize { private static $sql; private $userid; private $getuser; public function __construct($live=TRUE) { if(self::$sql == NULL) self::$sql = new MySQL; if($live == TRUE) { session_start(); if($_SESSION['userid'] != NULL) { echo("Session Recognized."); $this->userid = $_SESSION['userid']; $user = self::$sql->fetch("SELECT * FROM user WHERE id = ".$this->userid); if($user->getnumrows != FALSE) $this->getuser = $user->getrow(); else { echo("User Authentication Failed"); $this->userid = NULL; $_SESSION['userid'] = NULL; } } else $this->userid = NULL; echo("USER ID: ".$this->userid); } } //...continues with other methods/functions. I am running this class on an index.php page with a CSS tab-strip. I can log-in to the index page just fine, but when I try to 'reload' the page through navigation the tab-strip, I lose all session information and am kicked out to the login screen again... ...I'm a bit baffled honestly... ...here is the initialization of the index page include("PHPClasses.php"); $action = @$_GET['action']; $tab = @$_GET['tab']; if(!$tab) $tab = "units"; $user = new initialize(); $query = $user->getconnection(); $validate = $user->getuserid(); //...page execution If $validate returns NULL, I kick a person out of the index page and return them to the login screen... The $user->getuserid(); method looks like: public function getuserid() { return $this->userid; } ...and is part of the initialize class. Quote Link to comment Share on other sites More sharing options...
fert Posted March 8, 2007 Share Posted March 8, 2007 session start has to be at the very top of your page Quote Link to comment Share on other sites More sharing options...
mem0ri Posted March 8, 2007 Author Share Posted March 8, 2007 So you're telling me that ABSOLUTELY NOTHING can come before the session_start()? As in...I can't include files...or start a class that initializes by calling session_start? Quote Link to comment Share on other sites More sharing options...
mem0ri Posted March 8, 2007 Author Share Posted March 8, 2007 I would like to thank fert for taking so much time to enlighten me with his well-thought out reply... ...the problem...in case anyone was actually wondering...was that my $user->getnumrows command was supposed to be $user->getnumrows() No, session_start() does not need to be at the top of the page before everything and yes, it can be instantiated in a class. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.