• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 281
  • Last Modified:

Sessions Expire - How do I set session times to be different then server session timeout.

I am currently developing some PHP/MySQL based sites.  Everything is going smoothly except I have problems with session timeouts.  the session_start(); command is the first thing on all the pages of the site, and a session will last without issue for the duration defined by the php.ini session.  Then, the session expires.  Even if the user has been active in the web-app.  

How do I ensure that any activity on the site resets the session timeout so that users don't get logged off mid stream?  

How do I extend the session timeout on a per site basis regardless of the "session.gc_maxliftime" and or session.cache_expire settings in php.ini.  

On my test server, I can play with the ini file, but on hosted solutions I have no control.  I have yet to figure out how to permit users to remain logged in indefinetly as long as there is activity and having the session duration be 30 minutes regardless of the server side setting.

My appologies if this is a beginner type question, but I truly need an answer!

Thanks!
0
Ranidae
Asked:
Ranidae
1 Solution
 
jojuezCommented:
Can I see your connection string from your code?
0
 
dr_dedoCommented:
try this, would change the session timeout value to 30 minutes
ini_set(session.gc_maxlifetime, 30*60);
0
 
RanidaeAuthor Commented:
Hi Dr Dedo,

Thanks for the reply.  Session did last 30 minutes, regardless of activity.  Am I missing something in my code to reset that timer every time the session_start() is called so that for every page load the timer gets reset to 30 minutes.  Basically meaning the session would never end as long as there is 1 page load within the 30 minutes?

Jojuez, pardon my ignorance with the technical jargon as I am mostly self-edumacated.  When you say connetion string, I think of my MySQL connection, though I'm sure that's not what you mean.  Can you educate me?  Thanks.
0
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

 
Loganathan NatarajanLAMP DeveloperCommented:
can you tell me the max session timeout is set on your server?
0
 
RanidaeAuthor Commented:
According to phpinfo() against the server in question:

session.auto_start Off Off
session.bug_compat_42 On On
session.bug_compat_warn On On
session.cache_expire 180 180
session.cache_limiter nocache nocache
session.cookie_domain no value no value
session.cookie_httponly Off Off
session.cookie_lifetime 0 0
session.cookie_path / /
session.cookie_secure Off Off
session.entropy_file no value no value
session.entropy_length 0 0
session.gc_divisor 100 100
session.gc_maxlifetime 1440 1440
session.gc_probability 100 100
session.hash_bits_per_character 4 4
session.hash_function 0 0
session.name PHPSESSID PHPSESSID
session.referer_check no value no value
session.save_handler files files
session.save_path /...insert path here :)
session.serialize_handler php php
session.use_cookies On On
session.use_only_cookies Off Off
session.use_trans_sid 0 0


This is the information I believe is relevent.  Am I missing something?

0
 
RanidaeAuthor Commented:
The sequencing in setting the seesion.gc_maxlifetime is important.  Inittially, I had this value coming after session_start.  maxlifetime should come first.
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now