freebsdntu Posted December 17, 2007 Share Posted December 17, 2007 I have created a user class for user,in the class, there are profile attributes like names,email,etc and I also have get and set method for each of the attribute. Besides those, there are also user action methods like browseProfile,editProfile,etc When a user log in,I will instantiate a user object,the problem is how to remember the object so that other php files can also use it?I have tried something like this:$_SESSION['user'] = $user, where the $user is the object.But id did not work. Does anybody have any suggestion on how to do this? Thank you very much! Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 17, 2007 Share Posted December 17, 2007 the above should work does, the only catch is that the file that has the object definition should be above session_start(); so include("filename.php"); session_start(); Quote Link to comment Share on other sites More sharing options...
freebsdntu Posted December 17, 2007 Author Share Posted December 17, 2007 Thank you for your reply,rajivgonsalves .I tried your method, but got this: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent I remember I read somewhere that session_start() should always be the first statement,I don't know whether it is due to this reason. Also,does that mean I must include the file in every php file that I am gonna use the object? Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 17, 2007 Share Posted December 17, 2007 make sure there is no output to the browser in the included file just the class definition... Quote Link to comment Share on other sites More sharing options...
freebsdntu Posted December 17, 2007 Author Share Posted December 17, 2007 Oh,sorry,I got it wrong,that warning came because I output something before calling session_start() in the file before redirection. But another problem I discovered is that if I invoke methods like $user -> getUsername(), it returns empty string, is this the problem with the $user object? Quote Link to comment Share on other sites More sharing options...
freebsdntu Posted December 17, 2007 Author Share Posted December 17, 2007 Ah,thank you very much,rajivgonsalves,I got it working now.Thank you very much! Quote Link to comment 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.