|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-09-04 11:25 UTC] jani@php.net
[2009-09-04 11:26 UTC] jani@php.net
[2009-09-12 01:00 UTC] php-bugs at lists dot php dot net
[2009-09-20 17:26 UTC] wouter at prepaidwebhost dot nl
[2014-10-26 22:40 UTC] webmaster at tubo-world dot de
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 17:00:01 2025 UTC |
Description: ------------ PHP SESSION variable $_SESSION['user_level'] is not saved after the page is redirected using header(location: ...). Session_write_close()is used right before redirect. After redirect die() is called. After a second attempt at login, everything works! Reproduce code: --------------- <?php // If login successfully -> // Change session properties $_SESSION['user_level'] = 7; // Force session to save changes before redirection session_write_close(); // REQUIRED // Regenerate session id for security + fix bug in which some session variables are lost during redirect session_regenerate_id(true); // Redirect to Access main page header('Location: http://www.domain.com/access/main.php'); die(); ?> Expected result: ---------------- At the new page (the one the user was redirected to) the $SESSION['user_level'] should == 7. However, the session variable was not saved, as the user is redirected back to the login page. After a second attempt at logging in, everything works as expected. Actual result: -------------- Redirected back to login page, because when php checked if the user had the proper credentials if ($_SESSION['user_level'] != 7) { // redirect back to login page } Other improtant information: session_start(); is called on every page.