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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:35:59+00:00 2026-05-12T23:35:59+00:00

When a user logs in on our website, I want to change the session

  • 0

When a user logs in on our website, I want to change the session ID but keep whatever data is in the session. I want to do this for two reasons:

  1. To prevent a user account to be used at multiple places simultaneously (because if two people are using the same account, the actions of one will undermine the actions of the other).
  2. To let the user continue what he/she was doing on another computer (e.g moving from home computer to work).

These might seem contradictory, but really aren’t if you think it through.

The problem is as follows; to get to the data that is currently in the session, I have to call session_start(). This means I cannot call session_id() afterwards to set a new session ID. Any ideas how to transfer the session data and change the session ID.

Update: I need to be able to choose the session ID myself. session_regenerate_id() therefore won’t work.

  • 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-12T23:36:00+00:00Added an answer on May 12, 2026 at 11:36 pm

    You might be able to use session_regenerate_id():

    <?php
    session_start();
    
    $old_sessionid = session_id();
    
    session_regenerate_id();
    
    $new_sessionid = session_id();
    
    echo "Old Session: $old_sessionid<br />";
    echo "New Session: $new_sessionid<br />";
    
    print_r($_SESSION);
    ?>
    

    or even a cruder approach might work:

    // save the session
    session_start();
    $session = array();
    foreach ($_SESSION as $k => $v) {
      $session[$k] = $v;
    }
    session_commit();
    
    // create new session and copy variables
    session_id("new session id");
    session_start();
    foreach ($session as $k => $v) {
      $_SESSION[$k] = $v;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When a user logs in to my site I want a css styled button
Imagine an ASP.NET website which displays stock prices when a user logs in. Can
I need to start a program every time the user logs in, but I
I'm writing a report that shows total downtime for our website. When a user
On session timeout we re-direct to the login page and if the user logs
We have a website (foo.com) that does online training. A user logs in, then
I have the following scenario: A user on one our customer's website clicks a
Where I work they use the AppletContext.showDocument(URL) method when a user logs off our
We are seeing, under load, session data becoming corrupted or missing, but the sessions
When a user logs in, I give them a cookie named auth with a

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.