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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:38:04+00:00 2026-05-26T22:38:04+00:00

I have the function as follows: $sid = mysql_real_escape_string( $_COOKIE[‘session_id’] ); if( $sid )

  • 0

I have the function as follows:

 $sid = mysql_real_escape_string( $_COOKIE['session_id'] );
if( $sid ) { session_id( $sid ); }

// Start session
if( !session_start() ) { die( 'Session could not be started.' ); }
$sid = session_id();

// Validate session id
 $user = $this->validateSessionId( $sid );

if( $user ) {
    if( !$user['uid'] ) {
        trigger_error( '`Services->__construct()` - Could not find user by session id \''.(string)$sid.'\'.',
                E_USER_ERROR );
    }

    $_SESSION['uid'] = $user['uid'];
    $_SESSION['user_name'] = $user['name'];
    $_SESSION['user_email'] = $user['email'];
    $_SESSION['user_created'] = $user['created'];
}

// If no valid session id, user is anonymous
else {
    $_SESSION['user_name'] = 'Anonymous';
    $_SESSION['user_created'] = time();
}

When a user first logs in, a cookie is created for them called session_id with the id of their current session. This id is also added to a database table. My understanding is that the session eventually expires on both the client and the server, but a cookie and a database entry can be set to last as long as I’d want.

validateSessionId checks a table of session ids in the database. If the session is found, and hasn’t last been accessed more than 30 days ago (it’s removed from the table if so), an associative array from the user list representing the user associated with that session id. That user’s data is then loaded into the current session.

Am I understanding the workings of this correctly?

  • 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-26T22:38:05+00:00Added an answer on May 26, 2026 at 10:38 pm

    The whole session_id() business can be avoided. PHP will automatically check for the presence of a session cookie when you call session_start(), and retrieve the session’s ID at that time. You’re just duplicating what’s already done for you.

    Your code presumes that the cookie PHP is sending out to track the session is actually a permanent cookie. Usually PHP sends out a session cookie only (e.g. delete when browser is closed). As such, the user will not have ANY session cookie when they come back to the site, and will get a brand new session each time.

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

Sidebar

Related Questions

I have a function in a native DLL defined as follows: #include <string> void
I have a DLL which provided a decoding function, as follows: function MyDecode (Source:
I have code as follows: $(#item_select).change(function() { var params = $(#item_select option:selected).val(); $.post('/account/ar_form.php', {idata:
I have a struct as follows, with a pointer to a function called length
I have a function that is set up as follows function mainFunction() { function
If I have a jQuery plugin as follows: (function($) { $.fn.somefunction = function(text, options){
I have function as follows: Mask (sender) { var error= false; var regex =
I have a function as follows: $(document).on(click, .songTilesGenreContainer, function () { if ($(this).find(.actualTilesContainer).hasClass(minimalized)) {
I have a function that uses the ... rest argument as follows: public function
I have this function whose essential operations are outlined as follows: function render($index) {

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.