Quick Session Question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
seodevhead
Forum Regular
Posts: 705
Joined: Sat Oct 08, 2005 8:18 pm
Location: Windermere, FL

Quick Session Question

Post by seodevhead »

Hey guys... I have a page on my site that allows a user to submit a form... but I only want the person to be able to submit the form once every 24 hours. So as a way to enforce this, I am using a session variable.

How it works:
1. User submits form. Session variable is set to time();
2. If user submits form again, the php asks if isset($_SESSION['formSubmitTime']) and if so, then asks if $_SESSION['formSubmitTime'] < time()*60*60*24.

My question:

Is it okay to set a session variable to last 24 hours? I dunno why it just seems like 24 hours is a long time to maintain a session, am I wrong? Thanks for any advice on this matter.
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

This very forum's session lasts for about 14 days...
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

I have a feeling that closing and re-opening your browser may force a new session anyway... but I could be wrong. Have you considered setting a cookie?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

How come you think your session lasts 24 hours? All you are doing is setting a timestamp, nothing more and nothing less. Reguardless, there is nothing wrong with having a session last more than 24 hours.. often enough I have firefox open on devnet for several days.
Post Reply