Syphon Posted October 17, 2007 Share Posted October 17, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/73702-solved-php-5-session-issue/ Share on other sites More sharing options...
freakstyle Posted October 17, 2007 Share Posted October 17, 2007 lets see some code <?php // this doesn't work unless your defining it elsewhere? $_SESSION["User"] = myObject; and maybe the output of your print_r? Quote Link to comment https://forums.phpfreaks.com/topic/73702-solved-php-5-session-issue/#findComment-371874 Share on other sites More sharing options...
Syphon Posted October 17, 2007 Author Share Posted October 17, 2007 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; } } Quote Link to comment https://forums.phpfreaks.com/topic/73702-solved-php-5-session-issue/#findComment-371879 Share on other sites More sharing options...
SirChick Posted October 17, 2007 Share Posted October 17, 2007 $_SESSION["User"] its : just to try type: Echo $_SESSION["User"]; see if it echo's Quote Link to comment https://forums.phpfreaks.com/topic/73702-solved-php-5-session-issue/#findComment-371885 Share on other sites More sharing options...
atlanta Posted October 17, 2007 Share Posted October 17, 2007 yea just try using the "ECHO $_SESSION;" and see what your output is Quote Link to comment https://forums.phpfreaks.com/topic/73702-solved-php-5-session-issue/#findComment-371892 Share on other sites More sharing options...
Syphon Posted October 17, 2007 Author Share Posted October 17, 2007 $_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. Quote Link to comment https://forums.phpfreaks.com/topic/73702-solved-php-5-session-issue/#findComment-371893 Share on other sites More sharing options...
corbin Posted October 17, 2007 Share Posted October 17, 2007 It's serialized... $_SESSION["User"] = serialize($this); Try using unserialize on the data before using it. Quote Link to comment https://forums.phpfreaks.com/topic/73702-solved-php-5-session-issue/#findComment-371901 Share on other sites More sharing options...
Syphon Posted October 17, 2007 Author Share Posted October 17, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/73702-solved-php-5-session-issue/#findComment-371914 Share on other sites More sharing options...
corbin Posted October 17, 2007 Share Posted October 17, 2007 Oh sorry.... Didn't read the part you put about the data being deserialized later on ;p. Quote Link to comment https://forums.phpfreaks.com/topic/73702-solved-php-5-session-issue/#findComment-371917 Share on other sites More sharing options...
Syphon Posted October 19, 2007 Author Share Posted October 19, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/73702-solved-php-5-session-issue/#findComment-373549 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.