Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

stay logged in in php application for +1 week

We have a php application written in zend framework and are wondering what would be the best way if we wanted to keep our users logged in for more than a day, e.g. a week or even more.

Do we need sessions for that? (uses table space and memory?) or is it better to work with cookies? (security?)

like image 825
Jorre Avatar asked Jul 10 '10 10:07

Jorre


People also ask

How do I make PHP Keep me logged in?

Hence the user can log in without having to enter the Username and Password again until the life of that cookie expires. The example code given below is the way how to remember password checkbox works through PHP. $name = mysqli_real_escape_string( $connect , $_POST [ "user_name" ]);

How long should user sessions last?

It considers that longer idle time outs (15-30 minutes) are acceptable for low-risk applications. On the other hand, NIST recommends that application builders make their users re-authenticate every 12 hours and terminate sessions after 30 minutes of inactivity.

How to create Remember Me in PHP?

A more secure way to implement the remember me feature is to store a random token instead of a user id in both cookies and database server. When users access the web application, you match the cookies' tokens with those stored in the database. Also, you can check the token's expiration time.


1 Answers

HTTP is stateless, meaning the webserver will forget who you are after it served your request. Sessions are way around this. When using Sessions, browser and server will exchange an identifier on each request that lets the webserver connect previously stored data to this particular requestor.

The ID is usually stored in Cookie. Set your Session Cookie to expire in one week and you are all set for keeping your users logged in for a week.

See

  • PHP Manual on Session Handling
  • “Keep Me Logged In” - the best approach
  • Keep Accounts Logged In
like image 145
Gordon Avatar answered Sep 22 '22 06:09

Gordon