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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:00:30+00:00 2026-05-24T17:00:30+00:00

I have some basic session handling in my application. In each page I check

  • 0

I have some basic session handling in my application. In each page I check if the user is logged in. If they are then they’re already identified by $_SESSION['user_id'], and their login/logout is recorded in a MySQL table.

I would also like to record visits by guests (not logged in) based on a unique id.
I had assumed that once session_start() is called that an internal session_id is automatically generated and that calling session_id() I could retrieve this. But this just gives an “undefined variable” error, so I guess I have to set it manually..? If so then what’s the best way so that it will be a unique ID, or what is the usual method?

Thanks for any 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-24T17:00:30+00:00Added an answer on May 24, 2026 at 5:00 pm

    There are 2 ways to use sessions and session id’s in PHP:

    1 – Auto generate the session ID and get it:

    session_start();
    $id = session_id();
    

    2 – Set the session ID manually and then start it:

    session_id( 'mySessionId' );
    session_start();
    

    If you intend to set the session ID, you must set it before calling session_start();
    If you intend to generate a random session_id (or continue one already started in a previous page request) and then get that id for use elsewhere, you must call session_start() before attempting to use session_id() to retrieve the session ID.

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

Sidebar

Related Questions

I have this classic ASP web application. Each user must login and their most
Hi have some forms that I want to use some basic php validation (regular
Currently, I have some basic code to play a simple tone whenever a button
I have some questions about basic CSS that I was unable to understand or
For my university assignment I have to design some basic managment system for sicknesses
I have a storyboard(1) that does some basic animations in 2 seconds. I want
Dup of Some Basic PHP Questions Hello, I have a heap of tinyint fields
I have a Rails app with some basic models. The website displays data retrieved
This is a really basic question but... I have some code like this var
I have a basic model in which i have specified some of the fields

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.