大家好,又见面了,我是全栈君。
项目在php7.1 版本正常,迁移服务器php 7.2 报错
Maybe it’s a warning but with Tracy I have an error.
To solve this I put
session_write_close();
beforesession_set_cookie_params();
. It’s not a good fix but it’s works
session_name()
as well assession_set_cookie_params()
are always nonesense if the session is already running.翻译: session_name()以及
session_set_cookie_params
()总是不存在意义的,如果会话已在运行。
I had a similar problem but finally found a way through. The code below was my first approach that gave me errors.
static function startmysession($lifetime, $path, $domain, $secure, $httponly){
session_set_cookie_params($lifetime, $path, $domain, $secure, $httponly);
session_regenerate_id(true);
if(!isset($_SESSION)){
session_start();
}
}
Now Earlier versions of php overlooked our mistake(We were practically renaming and giving a session that already exists properties which is very wrong. So how did i solve this problem?(现在php的早期版本忽略了我们的错误(我们实际上是在重命名和提供一个已经存在的会话属性,这是非常错误的)。那么我是如何解决这个问题的呢?)
static function startmysession($lifetime, $path, $domain, $secure, $httponly){
if(!isset($_SESSION)){
session_set_cookie_params($lifetime, $path, $domain, $secure, $httponly);
@session_regenerate_id(true);
session_start();
}
}
I now bound the session_set_cookie_params()
just before session start and I test if the session already exists before doing so.(现在,我在会话开始之前绑定了会话session_set_cookie_params
(),并在此之前测试会话是否已经存在。)
My solution:
Originally:
$cookieParams = session_get_cookie_params();
session_set_cookie_params(
$seconds,
$cookieParams['path'],
$cookieParams['domain'],
$cookieParams['secure']
);
Now:
if(isset($_SESSION)) {
if ($seconds != 0) {
setcookie(session_name(), session_id(), time() + $seconds);
} else {
setcookie(session_name(), session_id(), $seconds);
}
} else {
$cookieParams = session_get_cookie_params();
session_set_cookie_params(
$seconds,
$cookieParams['path'],
$cookieParams['domain'],
$cookieParams['secure']
);
}
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/111572.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...