問題描述
這真的讓我很煩惱.已經好多年了.無論我用 core.php 還是 php.ini 做什么,我的登錄都會在大約一個小時后超時——通常是.一些相同代碼和配置的部署在相當長的時間后超時.
This is really bugging me. Has been for years. No matter what I do with core.php or php.ini, my logins timeout after about an hour - usually. Some deployments of identical code and configuration timeout after a respectable amount of time.
這是我目前在一個網站上的內容 - 大約一個小時后超時:
This is what I have at the moment on one site - timed out after about an hour:
session.gc_divisor 1000
session.gc_maxlifetime 86400
session.gc_probability 1
Configure::write('Session.timeout', '28800');
Configure::write('Session.checkAgent', false);
Configure::write('Security.level', 'medium');
另一個 - 持續了一夜:
And another - lasted all night:
session.gc_divisor 100
session.gc_maxlifetime 14400
session.gc_probability 0
Configure::write('Session.timeout', '315360000');
Configure::write('Session.checkAgent', false);
Configure::write('Security.level', 'medium');
現在,在您興奮地說嗯,答案就在 Session.timeout 值中"之前,讓我告訴您,該站點通常會在大約 20 分鐘后超時!
Now, before you get excited and say, "Well, the answer is there in the Session.timeout value", let me tell you that this site usually times out after about twenty minutes!
推薦答案
我在共享主機上讀到過,其他應用程序可以通過清除 php 定義的會話目錄來重置會話.Rowlf 在他的回答中提到了這一點.
Somewhere I read that on shared hosting, other applications can reset the session by clearing the php-defined session directory. This was alluded to by Rowlf in his answer.
CakePHP 提供了配置會話處理方式的選項.在 core.php
中,我將其更改為 'cake'
(默認為 'php'
):
CakePHP offers the option to configure the way sessions are handled. In core.php
I changed this to 'cake'
(by default it is 'php'
):
/**
* The preferred session handling method. Valid values:
*
* 'php' Uses settings defined in your php.ini.
* 'cake' Saves session files in CakePHP's /tmp directory.
* 'database' Uses CakePHP's database sessions.
*/
Configure::write('Session.save', 'cake');
我還確保會話超時和相應的 php.ini 值相同:
I also ensured that the session timeout and the corresponding php.ini values are the same:
/**
* Session time out time (in seconds).
* Actual value depends on 'Security.level' setting.
*/
Configure::write('Session.timeout', '86400');
到目前為止,系統還沒有退出.
So far, the system hasn't logged out.
這篇關于CakePHP 的身份驗證超時問題的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!