Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1008547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:47:16+00:00 2026-05-16T08:47:16+00:00

I am using 2 variables in cookie (7 day expiration) which is user id

  • 0

I am using 2 variables in cookie (7 day expiration) which is user id and hash. Hash is sha1 encode of user agent and user id. In this case some hacker can login who is know stolen cookie’s browser. Which way should I follow or which practice is best for remember me security problems?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T08:47:17+00:00Added an answer on May 16, 2026 at 8:47 am

    While you can hash a user_id and secret_key, anyone who intercepts this cookie can log in to your application. In addition to this, you can make it so that your remember me cookies go stale very quickly. No one likes a stale cookie.

    You can store the time stamp of each user’s last visit in your database and in the cookie. Each time you read the cookie to log the user in, you check to see that both timestamps match. If they don’t, deny the user. If they do, update the timestamps.

    Using this method, any time your user returns to your site, all old cookies go stale. A hacker that has intercepted a cookie now has a worthless stale cookie because he does not know the exact time stamp in the current cookie. Of course, the hacker can use a fresh cookie as much as he wants until the user logs back in.

    //check for cookie
    if(isset($_COOKIE['remember_me'])) {
       // get hash and time stamp from cookie
       $hash = substr($_COOKIE['remember_me'],0,40);
       $last_visit = substr($_COOKIE['remember_me'],41);
    
       // query your db with $hash and $last_visit
    
       // if hash and time stamp match up
          // log in
    
          // store the current time stamp in a variable to use for both
          $time = date("Y-m-d H:i:s");
          // update the time stamp in your cookie
          $cookie = $pass . "-" . $time;
          setcookie('remember_me', $cookie, time()+60*60*24*100, '/');
          // update the time_stamp in your database
       else {
          // remove the remember me cookie
          setcookie('remember_me', '', time()-42000, '/')
       }
    

    This method offers a small amount of security, and should certainly be used along side methods proposed in other answers. A hashed key should be stored in the cookie. A remember me cookie cannot be perfectly secure, so password re-entry should be required for any additional access to highly sensitive data or application features.

    I also recommend naming your cookie something besides ‘remember_me’ to make it a little harder to find. While it does not add much security, if any, naming your cookie ‘ht33424’ takes just as long as naming it ‘remember_me’ or ‘hack_me’.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble using variables in my SQL WHERE clause. I'm getting this error:
I always hear using global variables are dangerous. Does this apply to Drupal? Take
When setting session variables using cookie store in Rails 2, I can see the
When using suas in GAE and setting the flash_msg, for some reason the cookie
This question talks about using the system command and passing variables. Here is an
I'm trying to get the hang of using variables in C#, but have hit
Using local variables seems advisable in a partial that could be used application-wide to
I am using static variables in my app, lots of them. My question is,
I'm using global variables to pass around a response from a AJAX call: window.response
I have been using SESSION Variables to enter data with loginName as way to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.