Current location: Hot Scripts Forums » Programming Languages » PHP » Working with sessions in login form


Working with sessions in login form

Reply
  #1 (permalink)  
Old 07-14-06, 05:15 AM
zoliky's Avatar
zoliky zoliky is offline
Aspiring Coder
 
Join Date: Jun 2006
Posts: 537
Thanks: 0
Thanked 0 Times in 0 Posts
Working with sessions in login form

I have a login form.
I need to store all login data in sessions. I don't want to use cookies.

The session live until browser not closed. Exist a way to add a life time for sessions? ex. The session need to live 15 minutes.

With cookies I type the following to do this:
setcookie('username', activ, time()+900);

Thanks !
Reply With Quote
  #2 (permalink)  
Old 07-14-06, 05:18 AM
zitwep zitwep is offline
Wannabe Coder
 
Join Date: Aug 2005
Posts: 108
Thanks: 0
Thanked 0 Times in 0 Posts
ITs a PHP Settings I think you can change in your php.ini

The function should be called session.cache_expire .

Correct me if I am wrong nybody
Reply With Quote
  #3 (permalink)  
Old 07-14-06, 05:34 AM
zoliky's Avatar
zoliky zoliky is offline
Aspiring Coder
 
Join Date: Jun 2006
Posts: 537
Thanks: 0
Thanked 0 Times in 0 Posts
i don't have access to php.ini

I need to set a session with 15 minute life.
Reply With Quote
  #4 (permalink)  
Old 07-14-06, 05:38 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Reply With Quote
  #5 (permalink)  
Old 07-14-06, 07:00 AM
zoliky's Avatar
zoliky zoliky is offline
Aspiring Coder
 
Join Date: Jun 2006
Posts: 537
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks nico_swd, the article is good.
I have a session now with 2 minutes lifetime.

The session:
PHP Code:

$garbage_timeout 120// 2 minutes

ini_set('session.gc_maxlifetime'$garbage_timeout);

$cookie_path "/";
$cookie_timeout 120// in seconds
session_set_cookie_params($cookie_timeout$cookie_path);

session_start(); 
When user login to page, a session created with 2 minutes life time.
Ok.. When user click on a link after login I want to update this session time and I want to add +2 minutes.

This mean when user inactive for 2 minutes is redirected again to login page.

Thanks !

Last edited by nico_swd; 07-14-06 at 07:06 AM. Reason: [php] wrappers.
Reply With Quote
  #6 (permalink)  
Old 07-14-06, 09:43 AM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
PHP Code:

 $garbage_timeout 120// 2 minutes 

ini_set('session.gc_maxlifetime'$garbage_timeout); 
Setting the gc_maxlifetime to a small value does not have an effect on the functioning of your forced logout in the way you expect.

There is a common problem with this. On shared hosting and you are using the default session.save_path (on shared hosting you should set this to be within your own web space to avoid this problem) and all the session files are in one location, the shortest session.gc_maxlifetime is used. If someone else is using a longer session.cookie_lifetime and the garbage collection occurs, their session files will be deleted and they and their users will wonder why their sessions were canceled.

Note, based on direct repeatable observation, at least on Windows based PHP hosting, and I suspect on all PHP hosting, if someone is viewing a web page that is using sessions and he keeps the page open longer then the gc_maxlifetime (takes a long time to fill out a form or goes on a break) and it is a busy web server (counting all sites/domains using sessions) so that enough sessions are opened so that garbage collection occurs, the session files that are old enough will be unconditionally deleted. When this occurs the session no longer exists and anyone in the middle of a session that was deleted will receive an unexpected surprise.

Garbage collection was assumed (ASSUME = make an A**-out-of-U-and-ME) to work by only running every N sessions (N = session.gc_probability/session.gc_divisor)(despite the name probability, no randomness is involved, this is strictly a COUNTER) and it was ASSUMED that any session files older than session.gc_maxlifetime were safe to delete (there is no flagging or locking to insure that files for open sessions are not deleted. The session files are only accessed when they are created/read at the start of the session and are written to when you create a new session variable and when the session ends.) On a busy server the values for these should actually be increased.
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???

Last edited by mab; 07-14-06 at 09:46 AM.
Reply With Quote
  #7 (permalink)  
Old 07-17-06, 03:08 AM
zoliky's Avatar
zoliky zoliky is offline
Aspiring Coder
 
Join Date: Jun 2006
Posts: 537
Thanks: 0
Thanked 0 Times in 0 Posts
need help

Ok, I write what I need:

I need a Session cookie: PHPSESSID with 15 minutes life time.
I use the following lines to set life for cookie:

PHP Code:

session_start();

session_set_cookie_params(900"/"); 
900 seconds = 15 minutes.

Now, PHPSESSID live for 15 minutes. When user click on something (a link after cookie PHPSESSID exist) i want to update the PHPSESSID life and add 15 minutes again to PHPSESSID.

Please help me !
Thanks
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
php login form -tg PHP 3 06-30-06 02:24 AM
Hidden gliding admin login form patriksthlm JavaScript 1 08-09-05 12:40 PM
sessions not working, please help! tallpaul858 PHP 2 04-29-05 06:23 AM
Login script not working in frame... varial PHP 6 03-04-05 09:26 AM
form not working?? synna Script Requests 1 04-29-04 12:06 PM


All times are GMT -5. The time now is 07:21 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.