PHP session_id updated on upgrade

I am having problems with session_id()

which returns a new value every time the browser is refreshed / restarted.

Read this post here , but it won't fix the problem. I mentioned it all - browser accepts cookies, permissions are set correctly, no parameter value changes to sequential requests, etc.

Couldn't this be used if not used session_name()

or session_set_cookie_params()

right? Or maybe you need to tweak its initial configuration?

public static function init_session($name = FALSE, $lifetime = 10, $path = '/', $domain = FALSE, $secure = FALSE)   
{
    if (empty($name))
    {
        $name = APP_NAME;
    }

    if (empty($domain))
    {
        $domain = BASE_URL;
    }

    session_name($name);

    session_set_cookie_params($lifetime, $path, $domain, $secure, TRUE);

    session_start();

    echo session_id();
}

      

+3


source to share


1 answer


First of all, you set the session duration to 10 seconds , which means you get a new session every 10 seconds.

Side note: It is normal behavior for some browsers to reset session cookies when the browser is closed.

If you need your session to expand over multiple browser sessions, you need to use persistent cookies .



Example:

function init_session(/* ... */)
{
    if(!isset($_SESSION)) {
        session_start();
    }
    //Is it a running session?
    if(isset($_SESSION['somevalue'])) {
        //Everything is fine, session is loaded, no need to reload from cookies
    } else {
        if(isset($_COOKIE['yourcookiename'])) {
            //reload session from cookie
        } else {
            create_session();
        }
    }
}

function create_session()
{
    $_SESSION['somevalue'] = 1;
    //setcookie
}

      

Read http://www.allaboutcookies.org/cookies/cookies-the-same.html

+1


source







All Articles