最近我的php会话cookie停止在localhost上工作但是当我在线上传相同的文件时,它工作得非常好,我不知道我做错了什么。
这是我在登录时启动会话的代码。
<?php
define('sessionservername', '.example.com');
$Lifetime = 365 * 24 * 60 * 60; //31536000; // set cookie life time
$sessionTime = 365 * 24 * 60 * 60;
ini_set("session.gc_maxlifetime", $Lifetime);
ini_set("session.cookie_lifetime", $Lifetime);
ini_set("session.gc_divisor", "1");
ini_set("session.gc_probability", "1");
function sec_session_start(){
session_name();
$secure = false;
$httponly = false; /*This stops JavaScript being able to access the session id */
// Forces sessions to only use cookies.
if (ini_set('session.use_only_cookies', 1) === false) { header("Location: login.php?err=Could not initiate a safe session");exit();}
$cookieTimeer = 365 * 24 * 60 * 60; //31536000;
$cookieParams = session_get_cookie_params();
session_set_cookie_params($cookieTimeer, $cookieParams["path"], '.example.com', $secure, $httponly);
session_start();
}
?>
感谢每一页我添加了这一行
<?php
session_set_cookie_params($sessionTime, "/", sessionservername, $sessionsecure, $sessionhttponly);
session_start();
?>
答案 0 :(得分:1)
尝试删除此行或不执行localhost行 -
session_set_cookie_params($cookieTimeer, $cookieParams["path"], '.example.com', $secure, $httponly);
以上行设置仅为给定域保存cookie。