简体   繁体   中英

Set Session Cookie Expire

I have code that sets a session cookie, but I want it to persist beyond the single session. Is there a way to do this, or how would I convert it to a regular cookie that I can set to a longer expire time?

This is the code I call in the primary page to check for the session (age validation)...

session_start();
    if(! isset( $_SESSION['age_verification'] ) or $_SESSION['age_verification'] != true ) die( header("Location: checkage.php?url=http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]") );

Then from there, I call the following to check for the validation (form is not included as it is not necessary, but it creates the session cookie if yes is clicked).

<?php
session_start();

if( isset( $_POST['yes'] ) )
{
    $_SESSION['age_verification'] = true;

    if( isset( $_GET['url'] ) )
    {
        die( header('Location: ' . $_GET['url'] ) ); 
    } 
    else
    {
        die( header('Location: index.php') );
    }
}
elseif( isset( $_POST['no'] ) )
{
    $_SESSION['age_verification'] = false;
}

if( isset( $_SESSION['age_verification'] ) and $_SESSION['age_verification'] != true ) die( header('Location: http://www.bing.com') );

?>

Any advice would be appreciated.

Its not really something you necessarily want to do but this thread is quite relevant:

Set a cookie to never expire

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM