簡體   English   中英

修改 session.save_path 后 session_destroy 不起作用(其中 session 數據保存在服務器上)

[英]session_destroy not working after modifying session.save_path (where session data is saved on server)

我在網站的根目錄上創建了一個文件夾,其中 session 數據存儲在 public_html 之外。 我這樣做是為了使我網站上的會話持續更長時間,因為我遇到了一個問題,即它們會在 30 分鍾后超時。 我嘗試了很多方法來修復它,但在我嘗試下面的代碼之前沒有任何效果。 我正在使用以下代碼創建持續一天的會話,並且代碼停止了它們在 30 分鍾后超時的問題:

ini_set('session.save_path', '/home/server/.sessionsData');
ini_set('session.gc_maxlifetime', 86400); 
ini_set('session.cookie_lifetime', 86400);
ini_set('session.cache_expire', 86400);
ini_set('session.name', 'website');

session_start(); // Session ready to go!

進行此更改后,會話在 30 分鍾后不再超時,但我遇到了一個新問題,即破壞會話的“注銷代碼”不再像以前那樣結束會話。以下代碼是我'用於注銷和銷毀會話,但它不再像以前那樣工作:

session_start();
session_destroy();

header("location: https://website.com");

我應該怎么做才能破壞會話並刪除存儲在我的“/home/server/.sessionsData”文件夾中的相應 session 數據? 如果我將 go 放入該文件夾並直接刪除 session 數據文件,則在用戶瀏覽器中結束 session。

提前感謝您對此進行調查。

正如評論中提到的, Perhaps your ini_set() code, or at least the path changing part, needs to be in your log out script as well.

代碼形式:

ini_set('session.save_path', '/home/server/.sessionsData');
session_start();
session_destroy();

header("location: https://website.com");

session_unsetsession_destroy一起使用,是實際清除 SESSION 數據的有效方法。

session_start();
session_unset(); //--> frees all session variables currently registered.
session_destroy(); //--> destroys all of the data associated with the current session. It does not unset any of the global variables associated with the session, or unset the session cookie.

我還閱讀了 PHP 手冊評論,以下內容可以幫助頑固的瀏覽器:

session_write_close(); //--> End the current session and store session data.
setcookie(session_name(),'',0,'/');
session_regenerate_id(true);  //--> replace the current session id with a new one, and keep the current session information.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM