Jump to content

Unable to solve Session Problem


mem0ri

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/41711-unable-to-solve-session-problem/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.