skip to Main Content

I have just moved the dev site over to my linux server for production but the sessions don’t seem to be sticking for very long. I am guessing it is the server settings and not the php because it does the same thing with the plesk panel. Whenever a script is executed the sessions seems to get unset. I see nothing in the error log so not sure what it is. It all worked fine on wamp. Anyway I uploaded the php.ini file which was in the wamp server as it had all the settings i needed and all was working on localhost. Not sure what the problem is and this is the final thing that I have to sort out before going into production. And just too add the sessions are being started as they last for a little bit just don’t stick around long.

Here is the relevent part of my login script just in case there is something wrong with the code:

 // if login is ok then we add a cookie 
if($flag == 0) {
 $pass = htmlspecialchars(mysql_real_escape_string($_POST['pass']));
 $username = htmlspecialchars(mysql_real_escape_string($_POST['username']));



  $_SESSION['username']=$username;
  $_SESSION['password']=$pass;

3

Answers


  1. Set a higher value for session.gc_maxlifetime in your php.ini file.

    And did you do session_start(); somewhere?

    Login or Signup to reply.
  2. Please make sure you started the session using session_start() (just to be sure)

    You should look at the setting (PHP.ini/phpinfo()): session.cookie_lifetime
    It defines the lifetime for the cookie to keep track of the session

    Login or Signup to reply.
  3. Make sure cookies are enabled

    Check your Cookies with firebug/cookie monster if you are using Firefox.

    make sure that you are using session_start() before any output is started

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search