Help(unsolved): set session expire time
Moderator: General Moderators
- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
Help(unsolved): set session expire time
I am having difficulty finding code to set session to expire after half an hour since last activity.
Last edited by raghavan20 on Wed Jul 27, 2005 3:32 pm, edited 1 time in total.
I've done it like this:
Code: Select all
if(isset($_SESSION['time'])){
$time=$_SESSION['time'];
if(($time+1800)<time()){
logout();
}else $_SESSION['time']=time();
}- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
I dont know whether I am explaining it properly to you guys. Anyway, I am telling you again with an example.
ex: If you are using a mailbox, you login and check a few mails and browse other sites and when you come back to the mailbox you may find your session has expired because of session inactivity timeout setting.
I just want the code to work with that.
ex: If you are using a mailbox, you login and check a few mails and browse other sites and when you come back to the mailbox you may find your session has expired because of session inactivity timeout setting.
I just want the code to work with that.
wwwapu's method should work.
On every page you check the timestamp stored in the session of the last view if its more than 30 minutes old you force them to log back in by expiring their login/explicitly logging them out. If they passed the test, you update the last viewed time with the current time.
On every page you check the timestamp stored in the session of the last view if its more than 30 minutes old you force them to log back in by expiring their login/explicitly logging them out. If they passed the test, you update the last viewed time with the current time.
Repeating myself again.
Logout being at its simplest
[EDIT] That session_set_cookie_params() seems great. I think I'm in love...[/EDIT]
If 1800 seconds have passed, then logout(). Else set new 30 minutes period to be used.wwwapu wrote:I've done it like this:Code: Select all
if(isset($_SESSION['time'])){ $time=$_SESSION['time']; if(($time+1800)<time()){ logout(); }else $_SESSION['time']=time(); }
Logout being at its simplest
Code: Select all
function logout(){
session_destroy();
}
Last edited by wwwapu on Wed Jul 27, 2005 11:38 am, edited 1 time in total.
- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
Following errors appear
The code used:
Warning: session_start(): open(D:\Program Files\PHP\sessiondata\sess_8fc6e67ac6f0f4f4326ae524b57b1e6d, O_RDWR) failed: Permission denied (13) in E:\Hosted_Web\LocalUser\omnisoftcouk\website\adminPage.php on line 8
Warning: session_start(): Cannot send session cookie - headers already sent by (output started at E:\Hosted_Web\LocalUser\omnisoftcouk\website\adminPage.php:8) in E:\Hosted_Web\LocalUser\omnisoftcouk\website\adminPage.php on line 8
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at E:\Hosted_Web\LocalUser\omnisoftcouk\website\adminPage.php:8) in E:\Hosted_Web\LocalUser\omnisoftcouk\website\adminPage.php on line 8
Warning: Unknown(): open(D:\Program Files\PHP\sessiondata\sess_8fc6e67ac6f0f4f4326ae524b57b1e6d, O_RDWR) failed: Permission denied (13) in Unknown on line 0
Warning: Unknown(): Failed to write session data (files). Please verify that the current setting of session.save_path is correct (D:\Program Files\PHP\sessiondata) in Unknown on line 0
<?
$expiry = time() + (60*30);
session_set_cookie_params($expiry);
session_start();
?>
If the code is wrong, pls give your suggestions
Did you read first two notes in manual? do it like
Marvellous, just fantastic. 
Code: Select all
session_set_cookie_params(30*60);
session_start();- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
(Session save config on Windows -- help needed)
We need someone who knows about configuring PHP sessions on Windows to help here.... I'm a Mac/Linux/BSD guy and have little clue what the right advice is here.