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

  • Home
  • SEARCH
  • 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 8701281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:21:35+00:00 2026-06-13T02:21:35+00:00

Currently, after a user logs in, I simply store the user’s ID number in

  • 0

Currently, after a user logs in, I simply store the user’s ID number in a cookie using the following PHP code:

setcookie('userid', "$userid", time()+60*60*24*7*2, '/');

The above code sets a cookie that lasts for 2 weeks and contains the user’s ID number (stored in the variable $userid) that is not private. It also allows the user to stay logged in for 2 weeks. I am aware that this is probably one of the least secure ways to set a cookie to indicate that a user is logged in, since one can simply change his or her cookie parameter and log in as any user he or she wishes.

Therefore, how do a I set a cookie that accomplishes everything my cookie above accomplishes but is also secure?

In other words, what is the best way for me set a cookie that is secure and allows me at the very least to identify the user’s ID number during his or her session? I would also like the cookie to last 2 weeks, so the user doesn’t have to keep logging back into my website.

  • 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-06-13T02:21:37+00:00Added an answer on June 13, 2026 at 2:21 am

    Use sessions instead. It’ll store a session ID in a cookie but all the actual data is stored on the server so nobody can mess with it.

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

Sidebar

Related Questions

I currently have the following code which delays showing a fixed bar after a
Currently I do the following: Create package using msbuild something.csproj /P:Configuration:Some /T:Package After that
This code get's the currently logged in user, using the Spring Security Plugin (acegi):
Currently GDB has an issue following child processes after a fork. A work around
I am currently using two catch blocks after a try block. The first catches
I'm currently thinking about caching most of my viewdata excpt user specific data after
After a user logs in to an app I am developing, based on their
I am currently playing a song using MediaPlayer which plays fine. On user selecting
I currently have a form that lets a user select an image. After the
My Devise + Omniauth setup currently uses the following path to log a user

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.