ttocskcaj Posted February 1, 2011 Share Posted February 1, 2011 I have two test files. First file: (test.php) <?php session_start(); function __autoload($class) { include "../libs/$class.php"; } $_SESSION = new session("ttocskcaj",84824526893564); echo "Welcome ".$_SESSION->getUsername(); echo '<p><a href="test2.php">Test 2</a></p>'; Second File (test2.php) <?php session_start(); function __autoload($class) { include "../libs/$class.php"; } print_r($_SESSION); echo "Welcome ".$_SESSION->getUsername(); echo '<p><a href="test.php">Test 1</a></p>'; But the second file just returns this; Array ( ) Fatal error: Call to a member function getUsername() on a non-object in C:\xampp\htdocs\main\zend\TFFW\public\test2.php on line 4 Here's the session class https://github.com/ttocskcaj/The-Forum-Framework/blob/master/libs/session.php Is it even possible to save objects in a session? If so, what's going wrong? Quote Link to comment https://forums.phpfreaks.com/topic/226324-session-object-not-working/ Share on other sites More sharing options...
suma237 Posted February 1, 2011 Share Posted February 1, 2011 object is not created in the file test2.php Quote Link to comment https://forums.phpfreaks.com/topic/226324-session-object-not-working/#findComment-1168255 Share on other sites More sharing options...
PFMaBiSmAd Posted February 1, 2011 Share Posted February 1, 2011 The class definition must be included before the session_start() statement AND $_SESSION is the actual session variable array. You would need to use a specifically named session variable, something like - $_SESSION['user'] = new session("ttocskcaj",84824526893564); Quote Link to comment https://forums.phpfreaks.com/topic/226324-session-object-not-working/#findComment-1168257 Share on other sites More sharing options...
ttocskcaj Posted February 1, 2011 Author Share Posted February 1, 2011 Wow thanks. solved. I didn't realise $_SESSION had to be an array Quote Link to comment https://forums.phpfreaks.com/topic/226324-session-object-not-working/#findComment-1168269 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.