I have a webpage where I want to restore the session ID when a user logs in. The problem I encountered is running session_regenerate_id(); and then try adding $_SESSION['user'] = $row; where $ row is an array.
I tried everything in the book, for example, destroying a session, and then starting again. I have been working on it for at least 2 hours and I have no solution.
I removed a lot of irrelevant php and left some, so you get the gist of what I'm trying to do, but here's the script
<?php session_start(); if(!isset($_SESSION["CSRF"])){ $_SESSION["CSRF"] = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 10); } if(!empty($_POST)){ if($_POST["action"]==="login"){ //querying DB for $_POST values $stmt = $db->prepare($query); $result = $stmt->execute($query_params); $login_ok = false; $row = $stmt->fetch(); if($row){ $checked = //check password is okay if ($checked) { $login_ok = true; } } if($login_ok) { session_regenerate_id(); unset($row['salt']); unset($row['password']); $_SESSION['user'] = $row; } } }
I'm also out of luck.
<?php session_start(); if(!isset($_SESSION["CSRF"])){ $_SESSION["CSRF"] = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 10); } if(!empty($_POST)){ if($_POST["action"]==="login"){ //querying DB for $_POST values $stmt = $db->prepare($query); $result = $stmt->execute($query_params); $login_ok = false; $row = $stmt->fetch(); if($row){ $checked = //check password is okay if ($checked) { $login_ok = true; } } if($login_ok) { unset($row['salt']); unset($row['password']); $_SESSION['user'] = $row; $arr = $_SESSION; session_regenerate_id(true); $_SESSION = $arr; } } }
EDIT
Sorry, I did not specify the name, but basically I will try to save the current session in a variable, and I will regenerate the session identifier and add an attempt to add the saved session variable to a new session, however, the session identifier does not contain the old data, and I do not get any errors.
php session
Yusaf khaliq
source share