Save page status without refresh, after session expires

1

Here you can check if you are logged in

public function isLogged()
{

    if (isset($_SESSION['ccUser']) && !empty($_SESSION['ccUser'])) {
        if ($_SESSION['registro']) {
            $segundos = time() - $_SESSION['registro'];
            if ($segundos > $_SESSION['limite']) {
                unset($_SESSION['registro']);
                unset($_SESSION['limite']);
                unset($_SESSION['ccUser']);
                session_destroy();
                return false;
            } else {
                $_SESSION['registro'] = time();
                return true;
            }
        }
    } else {
        return false;
    }
}

If you do not redirect to login page and controller

 public function index(){
    $data = array();

    if(isset($_POST['email']) && !empty($_POST['email'])) {
        $email = addslashes($_POST['email']);
        $pass  = addslashes($_POST['password']);

        $user = new Users();

        if($user->doLogin($email, $pass )){
            header("Location: ".BASE_URL);
            exit;
        } else {
            $data['error'] = 'E-mail e/ou senha inválido.';
        }
    }
    $this->loadView('login', $data);
}


public function doLogin($email, $password)
{

    $sql = $this->db->prepare('SELECT * FROM user WHERE email = :email and password = :password AND TIPO = "USUARIO"');
    $sql->bindValue(':email', strtoupper($email));
    $sql->bindValue(':password', md5($password));
    $sql->execute();

    if ($sql->rowCount() > 0) {
        $row = $sql->fetch();

        $tempolimite = 1800; // equivale a 10 segundos

        $_SESSION['registro'] = time();
        $_SESSION['limite'] = $tempolimite;
        $_SESSION['ccUserPainel'] ='';
        $_SESSION['ccUser'] = $row['id'];
        return true;
    } else {
        return false;
    }
}

What I am not getting, and the client is registering a vehicle, then leaves a little, when the session expires again, I would like to rewrite and maintain the state of the page that was

This was my temporary solution, save only url index.php

$url = $_SERVER["REQUEST_URI"]; 
$_SESSION['url'] = $url; 

ai no

    <?php
    class loginController extends controller
   {

    public function index()
    {
        $data = array();

        if (isset($_POST['email']) && !empty($_POST['email'])) {
            $email = addslashes($_POST['email']);
            $pass = addslashes($_POST['password']);

            $user = new Users();

            if ($user->doLogin($email, $pass)) {
                if (isset($_SESSION['url']) && $_SESSION['url'] != "") {
                    if ($_SESSION['url'] == '/enginesystem/login') {
                        header("Location: " . BASE_URL);
                    } else {
                        header("Location: " . $_SESSION['url']);
                    }
                } else {
                    header("Location: " . BASE_URL);
                }
                exit;
            } else {
                $data['error'] = 'E-mail e/ou senha inválido.';
            }
        }
        $this->loadView('login', $data);
    }

    public function logout()
    {
        $user = new Users();
        $user->logout();
        header("Location: " . BASE_URL);
    }
    }
    
asked by anonymous 12.01.2018 / 20:11

1 answer

2

I suggest you use some front feature, it's less costly to implement in your application.

Use Session Storage or Local Storage is a good solution to use in your case.

See you later.

    
12.01.2018 / 20:17