我有這個功能來啓動安全會話:PHP設置cookie的壽命
function sec_session_start() {
$session_name = 'sec_session_id'; // Set a custom session name
$secure = false; // Set to true if using https.
$httponly = true; // This stops javascript being able to access the session id.
ini_set('session.use_only_cookies', 1); // Forces sessions to only use cookies.
$cookieParams = session_get_cookie_params(); // Gets current cookies params.
session_set_cookie_params($cookieParams["lifetime"], $cookieParams["path"], $cookieParams["domain"], $secure, $httponly);
session_name($session_name); // Sets the session name to the one set above.
session_start(); // Start the php session
session_regenerate_id(true); // regenerated the session, delete the old one.
}
如何設置我的餅乾到期每當用戶從我的應用程序導航離開或關閉瀏覽器?基本上,每次用戶訪問我的應用程序時,都需要重新登錄。
您可能希望使用'$ _SESSION'來代替。 '$ _COOKIES'只在到期時間後過期*。一旦瀏覽器關閉或到期後,$ _SESSION結束。 – Matt 2012-08-09 15:59:08
@Matt'$ _SESSION' *使用* cookies功能。這些是FastTrack在這裏特別設置的設置。會話不是一個獨立於Cookie的機制;他們只是巧妙地使用cookies和服務器端存儲。 – VoteyDisciple 2012-08-09 16:01:54
這是對同一問題 http://stackoverflow.com/questions/3177364/destroy-php-session-on-page-leaving – 2012-08-09 16:02:43