1
Here checks 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 and controller page
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’m not getting and, the customer is registering a vehicle, then comes out a little, when back expired to Session, would like to relocate and keep the status of the page that was
This was my temporary solution, save only url index.php
$url = $_SERVER["REQUEST_URI"];
$_SESSION['url'] = $url;
ai in the
<?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);
}
}
vo save only the same address $url = $_SERVER["REQUEST_URI"]; $_SESSION['url'] = $url; 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); }
– Junior Ramoty