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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.