My login system only logs in if I do it 2 times. In the first time, it doesn't log in (automatically).
I have a simple form with username and password, with action="login.php"
, which as you might think has the whole code for verify login, etc..and then, in the end, if everything is ok:
Cookie::set('page-main-login-cookie', serialize($arr), time()+60);
header('location: ../index.php');
In the index.php
(which contains the form that calls login.php
), in the top of the page:
ob_start(); session_start(); include('cookies.php'); include('sessions.php');
After the </html>
tag:
if(Cookie::Exists('page-main-login-cookie')){
$data = unserialize(stripslashes($_COOKIE['page-main-login-cookie']));
if($data['status'] == 1){
Cookie::set('email', $data['email'], time() + (86400 * 7));
Session::set('email', $data['email']);
echo "<script type='text/javascript'> page_redirect(); </script>";
}else{
echo "<script type='text/javascript'> page_error(); </script>";
}
Cookie::Delete('page-main-login-cookie', time() - 3600);
}
And while I'm writing this topic I wonder if the problem might be in the javascript. The code for page_redirect()
is the following:
function page_redirect(){
alert("Done!");
setTimeout(function(){
location.reload();
}, 1500);
}
What have I tried so far?
- Changed
header('location: ../index.php');
to header('location: http://www.mysite.com');
- Added
session_write_close();
after Session::set('email', $data['email']);
None of them worked.