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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:44:31+00:00 2026-06-02T10:44:31+00:00

I’m having trouble getting PHP’s session_regenerate_id() to work in an application I’m developing. The

  • 0

I’m having trouble getting PHP’s session_regenerate_id() to work in an application I’m developing. The application uses a (loose) self-made MVC framework and redirects all requests using .htaccess through the index.php file.

I’m trying to regenerate the session ID on logout but it isn’t working correctly.

Here is some code from my logout controller – the expired variable is a check for session timeout:

    session_regenerate_id(true);        
    if(isset($_SESSION['expired']))
    {
        $this->registry->template->expired = true;
    }

    session_unset();
    session_destroy();

Also relevant is the code from the beginning of the index.php file:

    session_cache_expire(20);
    session_start();
    session_name("TMU");
    //session_regenerate_id();

I’m echoing out the result of session_id() at the bottom of each page to see what it contains to test if it has been regenerated.

The session ID doesn’t change when you logout however. When you login again (even with another account) the session ID is the same.

You’ll notice the commented out fourth line of the index.php file – if I uncomment that line the ID appears to be regenerated on every page as it should. However, when I comment the line out again the session ID is once again the original ID from before I uncommented the line in the index file…

I’m just wondering how I can get session_regenerate_id() to work. It seems like it’s just not ‘committing’ the changed id. I’ve tried using session_commit() but I don’t understand how it works fully and it was giving me an error when I tried to destroy the session.

PHP 5.3.10 and apache 2.2.21

  • 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-02T10:44:32+00:00Added an answer on June 2, 2026 at 10:44 am

    After revisiting this topic several times, I have figured it out. There were two problems.

    1. session_regenerate_id() must be called before any HTML output is displayed and/or headers are sent. (It needs to be called as one of the first functions, just like session_start()).
    2. Order matters. session_name("TMU") needs to be called BEFORE session_start() to have the desired result – I didn’t catch this before.

    Basically what was happening to me was calling session_name("TMU") after session_start() was causing it to set TWO session ID cookies – two sessions – one named TMU the other just the default PHPSESSID. Changing the order fixed all my problems and regenerating the ID / destroying the old session works as expected now.

    For anyone having problems doing this I suggest you echo out the $_SESSION and $_COOKIE arrays to see what is happening in your particular application.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;

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.