Home  >  Article  >  Backend Development  >  Notes on session_start in PHP7!

Notes on session_start in PHP7!

藏色散人
藏色散人forward
2020-07-25 16:05:233461browse

Notes on session_start in PHP7!

PHP7 Notes on session_start will cause the browser page not to update

Related recommendations: " php session session (topic)

Please see the code

//PHP7中session_start 使用注意事项,
session_start([
    'cache_limiter' => 'private', //在读取完毕会话数据之后马上关闭会话存储文件//启用后,浏览器刷新时,页面将不再请求服务器刷新,只能使用CTRL+F5刷新才重新请求数据,慎用!
    'cookie_lifetime' => 3600 ,  //SessionID在客户端Cookie储存的时间,默认是0,代表浏览器一关闭SessionID就作废
        'read_and_close' => true   //在读取完会话数据之后, 立即关闭会话存储文件,不做任何修改//启用后不能修改,不能销毁SESSION
]);
$tmd = $_GET['tmd'] ?? 1;
refreshUrl("admin_login.php",$tmd);
/*浏览器刷新时,更新URL地址,防止页面缓存*/
function refreshUrl($url, $tmd)
{
    $waitTime = microtime(true) - $tmd;
    if ($waitTime > 1) {
        jmpUrl($url);
        die();
    }
}
/*url跳转加随机数,防止页面缓存*/
function jmpUrl($url)
{
    if (!strpos($url, '?')) {
        header("Refresh:0;url=" . $url . "?tmd=" . microtime(true));
    } else {
        header("Refresh:0;url=" . $url . "&tmd=" . microtime(true));
    }
}

Related topic recommendations:php session (including pictures Text, video, case)

The above is the detailed content of Notes on session_start in PHP7!. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete