Jump to content

[SOLVED] How to remember an object?


freebsdntu

Recommended Posts

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!

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?

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.