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!
LVL 2
RanidaeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.