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 7562085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:19:35+00:00 2026-05-30T13:19:35+00:00

Sorry for the newbie question! I’m making a small website that allows users to

  • 0

Sorry for the newbie question! I’m making a small website that allows users to create their own accounts. It’s not a banking system, and it’s unlikely that someone would want to hack it. That said, I am trying to make it reasonably secure, as there are plenty of bored script kiddies out there.

Could someone describe a basic workflow for a user logging in and having a cookie set that will keep them logged in for 30 days?

At the moment I have the following:

  1. Validate and sanitize inputted data.

  2. Check supplied credentials against bcrypt hashed password in DB.

  3. If correct then call "Login" function.

  4. Login function:

    a. Delete any session data from DB with userID (table with two columns: SessionString and UserID).
    b. Add new session data to DB (newy random generated string and UserID).
    c. Write random generated string and UserID to cookie.
    d. Set $_SESSION("UserID") with $userID.

But although the two cookies are being created and written to, the $_SESSION("UserID") remains blank… I’m guessing because I can’t write to $_SESSION any time I like?

And even once that’s fixed, how do I use the data stored in the cookie to log a user in? I’m guessing I don’t want to go to the DB on every page load. And it will still require me to create a database object to see if the credentials in the cookie are ok. Is this the right way to this?

Once again, apologies for the newbie question!


UPDATE:
Yes, I do understand the difference between $_SESSION variables and a cookies. I also have session_start() at the top of every page (right after <php with no blank lines). $_SESSION("UserID") just remains blank.

Here’s the code from the top of the page:

<?php
session_start();

if(!isset($_SESSION['initiated'])) {
    session_regenerate_id();
    $_SESSION['initiated'] = true;
} 

Thanks for the help.

  • 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-30T13:19:37+00:00Added an answer on May 30, 2026 at 1:19 pm

    First off, there is an important difference between a session and a cookie. When you use the $_SESSION[".."] you are creating a session (which lives on the server, compared to a cookie which lives on the client), even though the browser uses a cookie to keep track of the session id. To create a cookie you would use the setcookie() method.

    That said, I would recommend you to read through this article which is a step-by-step guide on how to create a secure login script, with persistence using a cookie for a “Remember me”-feature. Describe how to do it in detail would be to extensive for an SO answer im afraid.

    Side note:

    To be able to write to the session, you might have to call session_start(); prior to getting or setting a session variable using $_SESSION[".."].

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

Sidebar

Related Questions

Sorry for the second newbie question, I'm a developer not a sysadmin so this
first of all, sorry if that question is dumb but I´m a total newbie
I'm starting with developing, sorry about this newbie question. I need to create a
Sorry for the newbie question but still very new to Ruby and Mongo. Not
Sorry if this is a newbie question. I have a VB.NET subroutine that is
Sorry another newbie question that I couldn't seem to find an answer to on
sorry for a newbie question.. but Service by it's defenision meaning the same as
I'm really new to VSTO so sorry if this is a newbie question. I'm
Sorry for this not being a real question, but Sometime back i remember seeing
Sorry about this newbie question. Is there a way to execute multiple sentences at

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.