I used to do that to test if the user is logged in, and if so display his/her content:
if (login_check($conn) == true) {
// show content here
}
But since it failed sometimes and I wanted to know why, I changed it to
$loginErro = login_error($conn);
if (!$loginErro) {
// show content here
}
so I could get a number to know what the error was. But since then the errors increased. Many times the page says I'm not logged in, when in fact I'm logged in. I need to press F5 to refresh the correct session variable. The line that triggers the error in the login_error function is
if (!isset($_SESSION['user_id'])) {
return 4;
}
Why my user_id is not being updated, mostly in the first time after a while (the session's cookie timeout, probably)?
EDIT: Somehow I could isolate the problem. When calling window.open() function, I was using
window.open('some_php_file.php','');
It opens multiple copies of the same php file, but loads them all ok. Then I changed it to
window.open('some_php_file.php','some_php_file.php');
to prevent opening multiple copies of the same window. Now, I open the first copy ok. When I click the button to open the window again, it is logging off from the system! Still trying to understand what's going on...