1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Sessions are resetting on page refresh

Discussion in 'PHP & Perl' started by qlithe, Oct 7, 2015.

  1. qlithe

    qlithe Power Member

    Joined:
    Feb 14, 2012
    Messages:
    660
    Likes Received:
    97
    So I have a login system (php/mysql) that's been working fine.

    Yesterday I upgraded to a VPS and for some reason the sessions reset (people gets immediately logged out) after logging in and just loading another page

    Anyone got a clue? All PHP settings seem right
     
  2. AppCentral

    AppCentral Newbie

    Joined:
    Oct 7, 2015
    Messages:
    32
    Likes Received:
    8
    Without seeing the code, I'm assuming that nothing has been changed since the server migration. There's bound to be an error or warning available (If not, you should enable error reporting using

    PHP:
    error_reporting(E_ALL);
    ini_set('display_errors',1);


    Then check to see if you're getting any kind of errors or warnings, a common one after host migration is this one:

    PHP:
    Warningsession_start(): Cannot send session cookie headers already sent
     
  3. zotohost

    zotohost Registered Member

    Joined:
    Oct 25, 2015
    Messages:
    71
    Likes Received:
    4
    It may be caused by some PHP plugin / addon that you have installed on VPS.
     
  4. mantic0re

    mantic0re Junior Member

    Joined:
    May 29, 2015
    Messages:
    118
    Likes Received:
    9
    Have you checked if your session data is being stored at all or if it's just the login part that's malfunctioning? If you just installed a regular LAMP stack and used default settings there is no way that it could cause the issue you described.
     
  5. revproxy

    revproxy BANNED BANNED Jr. VIP Premium Member

    Joined:
    Nov 20, 2015
    Messages:
    396
    Likes Received:
    101
    Gender:
    Male
    check in php.ini:
    http://php.net/manual/en/session.configuration.php

    try to add this header:
    header('Access-Control-Allow-Credentials: true');
    if you use client js app like Angular check if you send this header:
    Access-Control-Allow-Credentials: true
     
  6. revproxy

    revproxy BANNED BANNED Jr. VIP Premium Member

    Joined:
    Nov 20, 2015
    Messages:
    396
    Likes Received:
    101
    Gender:
    Male
    and check if you start a session:
    session_start();

    check if cookies is works... becouse session_id stored in cookie