Jump to content

[SOLVED] PHP 5 Session Issue


Syphon

Recommended Posts

Hi all,

 

I'm having a problem using sessions. On my local Windows testing everything is fine, but once moved to the Linux "live" testing problems start coming up.

 

I create a user object and store it in the session using

 

$_SESSION["User"] = myObject;

 

ONLY the user session is being destroyed/lost during page navigation and refresh. On top of that whenever I use print_r() it displays a complete mess.

 

My theory is that the "mess" may indicate "bad storage" and PHP is automatically destroying it, or something else.

 

Any help would be appreciated. Thanks in advance.

Link to comment
Share on other sites

       

include "../lib/Functions.php";
include "../lib/DALC.php";
include "../lib/User.php";
include "../lib/Errors.php";

session_start();
//if(isset($_SESSION["User"])){header('Location: home.php');}

if($_POST["btnSubmit"]){

	$User = new User();

	$User->LoadUserByLogin($_POST["txtLogin"]);

	if ($User->LogUserIn($_POST["txtPassword"])){

		/*session_write_close();	
		header('Location: home.php');
		exit;*/

		print "Session Data: ";
		echo "<pre>";
		print_r($_SESSION);
		echo "</pre>";


	}else{

		echo "Your password or login are incorrect";

	}

}

 

 

 

 

 

******************

 

Now within the 'User Object this is the line of code that starts the session

 

 

function StartUserSession(){

			if ( $this->UserAuthenticated == true ){

				$_SESSION["User"] = serialize($this);

				return true;

			}else{

				return false;

			}

		}

Link to comment
Share on other sites

$_SESSION["User"]

 

its :

 

just to try type:

 

Echo $_SESSION["User"];

 

see if it echo's

 

The statement does echo but it's ugly. Instead of '=>' I get this mess

 

 

O:4:"User":15:{s:4:"DALC";O:4:"DALC":9:{s:16:"DataBaseUserName";s:11:"testuser";s:16:"DataBasePassword";s:16:"test123";s:12:"DataBaseHost";s:9:"localhost";s:8:"DataBase";s:11:"test";s:12:"myConnection";i:0;s:7:"myQuery";s:186:"SELECT UserID, UserLogin, UserFirstName, UserLastName, UserSALT, UserHASH, UserBiography, UserContactProfileID, UserLevelID, TimeStamp FROM users WHERE Active = 1 AND UserLogin = 'Admin'";s:8:"myResult";i:0;s:12:"myQueryCount";i:1;s:12:"errorHandler";O:6:"Errors":2:{s:13:"�Errors�Debug";b:0;s:17:"�Errors�ErrorList";a:0:{}}}s:9:"Functions";O:9:"Functions":1:{s:4:"DALC";O:4:"DALC":9:{s:16:"DataBaseUserName";s:11:"testuser";s:16:"DataBasePassword";s:16:"test123";s:12:"DataBaseHost";s:9:"localhost";s:8:"DataBase";s:11:"test";s:12:"myConnection";i:0;s:7:"myQuery";N;s:8:"myResult";s:0:"";s:12:"myQueryCount";s:1:"0";s:12:"errorHandler";O:6:"Errors":2:{s:13:"�Errors�Debug";b:0;s:17:"�Errors�ErrorList";a:0:{}}}}s:6:"UserID";s:8:"00000001";s:9:"UserLogin";s:5:"Admin";s:13:"UserFirstName";s:5:"Admin";s:12:"UserLastName";s:5:"Admin";s:8:"UserSALT";s:34:"8A0F6BE25D8C1D64ADCFA7A8C611190E06";s:8:"UserHASH";s:40:"f2d3fee60df2ee1b136833849e631a513e70217c";s:13:"UserBiography";s:5:"myBio";s:20:"UserContactProfileID";s:1:"1";s:11:"UserLevelID";s:1:"1";s:9:"TimeStamp";s:19:"2007-10-16 19:00:46";s:6:"Active";i:1;s:10:"UserLoaded";b:1;s:17:"UserAuthenticated";b:1;}

 

 

Now if I break the code by unserializing the object BEFORE the class definition is declared (_PHP_INCOMPLETE_CLASS_ Error) then it will output much cleaner.

Link to comment
Share on other sites

It's serialized...

 

$_SESSION["User"] = serialize($this);

 

Try using unserialize on the data before using it.

 

That does clean up the mess but does not solve the problem.

 

Once a user has been logged in they are redirected to the "home" page. The session and user data is outputted to this screen for testing. Upon refreshing or navigation ONLY the User session object is destroyed.

 

Will session_start(); work if it's run in an include file? All of my pages have a base "includes.php" file where session_start(); is called.

Link to comment
Share on other sites

This issue has been related to register_globals being turned "on" with the server environment. It's disabled on my machine which makes sense. My PHP variable $User was being overwritten with the serialized version of itself. Simply renaming one or the other variable fixed the issue. Or disabling register_globals could work too.

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.