PHP Sessions
Moderator: General Moderators
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
You can set the session timeout in the php.ini file. You can also do something programatic -- for example every time they acccess a page you check to see if the time in a timestamp saved in a session variable has been passed. If it has not then save a timestamp an hour in the future to that var. If you have passed the save timestamp then clear the session vars and redirect to the login page.BigAbe wrote:1) How do I handle timeouts and/or specifying how long I want the user to stay "logged in"?
No. Keep as little as possible and only temporary data necessary to maintain session context for the user.BigAbe wrote:2) Do you recommend keeping the connection data in a session variable? I have one main index page with tons of include() statements, so I can easily just keep the connection details there, but if there's an easier/better way of doing it, I'd love to hear your thoughts.
(#10850)
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Database connection details should be stored in an include file a folder below your server root. For example, if your server path is /var/www/public_html/ the you should put your connection details in /var/www/. This is just my opinion. I am sure there are many different, viable approaches to this question.
As for session data... the whole concept of a session is the time a user spends visiting your site. Their 'session' if you will, is the time they are at a particular position. Storing information outside the scope of the session is not a recommended use of session handling. Again, this is my opinion.
As for session data... the whole concept of a session is the time a user spends visiting your site. Their 'session' if you will, is the time they are at a particular position. Storing information outside the scope of the session is not a recommended use of session handling. Again, this is my opinion.
Bonus question
If on page 1 I declare
then go to page 2 and say
if I go to page 3, what should
display?
Just wondering...
Code: Select all
$_SESSION['var'] = 1;Code: Select all
$var = 2;Code: Select all
echo $_SESSION['var'];Just wondering...
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA