phpsessionredbean

How to reload session without re-login


I have this code:

<?php
$data = $_POST;
$lastchange = date('l jS \of F Y h:i:s A');
if(isset($data['do_change'])) {
    $user = R::findOne('users', 'login = ?', array($login));
    if ($user) {
        $user->lastchange = $lastchange;
        $user->login = $data['newlogin'];
        R::store($user);
    }
}
?>

After I update user data, the session data is not up to date. Can I somehow, after that script, end the session and start it again, without the user needing to login again?

This is the login part:

if (isset($data['do_login'])) {
    session_start ()
    if ($response != null && $response->success) {
        $user = R::findOne('users', 'login = ?', array($data['login']));
        if ($user) {
            if (($data['password'] == $user->password)) {
                $_SESSION['logged_user'] = $user;
                header('Location: pcab.php');
                exit;
            }
        }
    }
}

Solution

  • You don't need a session reload, you just need to update the session data after updating the user data.

    <?php
    $data = $_POST;
    $lastchange = date('l jS \of F Y h:i:s A');
    if(isset($data['do_change'])) {
        $user = R::findOne('users', 'login = ?', array($login));
        if ($user) {
            $user->lastchange = $lastchange;
            $user->login = $data['newlogin'];
            R::store($user);
            $_SESSION['logged_user'] = $user; // update the logged-in user
        }
    }
    ?>