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

Notes on session_start in PHP7!

藏色散人
Release: 2023-02-17 17:14:01
forward
3542 people have browsed it

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
]);
Copy after login
$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));
    }
}
Copy after login

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!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template