Jump to content

Problems with Sessions


BelovedDoll

Recommended Posts

Pesky me again.

 

This time I`d like to have my session code looked over. I`m having some problems with it. When a user logs into my website (provided they enter all the right information), they will log in no problem. However, the session doesn`t last as long as I`d like it and it seems to be unpredictable with how long it`ll last. Such as, one day it`ll last 5 hours even with closing the browser. The next day it might last 20 minutes. The next day it may log the person out if they close the browser. I`d looked around on the net to see what could be going wrong with my code but I guess I`m not getting it.

 

Any more epxerienced set of eyes want to look it over and give me their opinion:

function RemoveSession() {
        $_SESSION = array();
        if (isset($_COOKIE[session_name()])) {
           @setcookie(session_name(), '', time()+(60*60*24*365), '/');
        }
    }

 

Is it even possible to make a session last as long as cookies can? Like have it last a month even though the person closes the browser and shuts off their computer and doesn`t visit for a few days? I`d like to have it start out lasting a full month if possible.

Link to comment
Share on other sites

What is RemoveSession() intended to do?  If you want to change the session cookie attributes, there are configuration options described here: http://www.php.net/manual/en/session.configuration.php , with the default being "until the browser is closed".

 

Session life depends on two things - how long the cookie survives in the browser, and how long the session file lasts on the server.  The first depends on the cookie options, the second depends on your server's configuration, and sometimes can be beyond your control.

 

 

Link to comment
Share on other sites

  • 2 weeks later...
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.