Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-11-2010, 07:49 AM   PM User | #1
renu-86
New Coder

 
Join Date: Jan 2010
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
renu-86 is an unknown quantity at this point
code for session expire

i have got a login page with emAIL and password ..
can anyone suggest me a way to implement code for session to expire after 15 min when a peron is logged into the site if he is logged in for more than 15 min..

these are the two sessions in log in page .
$_SESSION['email']
$_SESSION['password']

below given is the code for log out page .
PHP Code:
<?php

session_start
();
session_unregister('email');
session_unregister('password');
session_destroy();
?>
thank you... any help will be appreciated . . .
renu-86 is offline   Reply With Quote
Old 02-11-2010, 08:14 AM   PM User | #2
kieran491
New Coder

 
Join Date: Jun 2008
Posts: 76
Thanks: 6
Thanked 6 Times in 6 Posts
kieran491 is an unknown quantity at this point
Hi there you may also want to recreate there session id with this simple command

PHP Code:
session_regenerate_id(true
the true argument will also delete the old session but this must all be done before you start printing out to the user as the cookie has to be resent
kieran491 is offline   Reply With Quote
Old 02-11-2010, 12:16 PM   PM User | #3
renu-86
New Coder

 
Join Date: Jan 2010
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
renu-86 is an unknown quantity at this point
thanks for the suggestion ..

can u pls make it more clear??
renu-86 is offline   Reply With Quote
Old 02-11-2010, 04:25 PM   PM User | #4
sitNsmile
Regular Coder

 
sitNsmile's Avatar
 
Join Date: Dec 2009
Location: Charlotte, NC
Posts: 354
Thanks: 19
Thanked 2 Times in 2 Posts
sitNsmile is an unknown quantity at this point
Session_register, Session_unregister are going out of date, recommended that it not replied upon anymore.

http://php.net/manual/en/function.se...unregister.php

or logging out though, you can use something like this,


PHP Code:
session_start(); 
session_unset(); 
session_destroy(); 
sitNsmile is offline   Reply With Quote
Old 02-14-2010, 06:28 AM   PM User | #5
renu-86
New Coder

 
Join Date: Jan 2010
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
renu-86 is an unknown quantity at this point
what i want to do is , after logging in with username and password , user will be in a page ,, if he / she remains logged in for 15 min , i want it to be automatically logged out and come backk to main page ...

tried the above code , not working..
renu-86 is offline   Reply With Quote
Old 02-14-2010, 07:34 AM   PM User | #6
SKDevelopment
Regular Coder

 
Join Date: Mar 2006
Posts: 238
Thanks: 3
Thanked 37 Times in 37 Posts
SKDevelopment has a little shameless behaviour in the past
1) You could try to redirect after some time using the header refresh or an Meta tags. You could redirect to a special page which would log out the user. From that page you could redirect to the main page using the header Location.

2) I would not recommend to store the login and password in the session variables after the successful authentication. Usually they are not necessary any more after the authentication is passed. Also at some servers sessions could be badly configured so it could be possibly not really safe.

You could simply store some flag e.g. $_SESSION['login_success'] instead. If this flag is set and e.g. equal to 1, the user is logged in.

3) Advice given by Kieran491 to use session_regenerate_id() after successful authentication is also very good. It addresses session security (not redirect after 15 min) but the advice is good. Using this function helps to prevent session fixation attacks. Simply run this function after you have checked the user authentication was successful in your script (but before any output is sent by the script to the browser).

Please ask questions if something is not clear.
__________________
PHP Programmer

Last edited by SKDevelopment; 02-14-2010 at 07:43 AM..
SKDevelopment is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:32 PM.


Advertisement
Log in to turn off these ads.