php - URL opening in all browsers even when user not logged in?
873
My url is opening in all browsers even when I am using sessions. Ex abc.com/123.php without users logged in. This opens up in all browsers. I am using this code.All codes are in < php open/close tags ok codes which ia m using are
<?php
session_start();
if (isset($_SESSION['LAST_REQUEST_TIME'])) {
if (time() - $_SESSION['LAST_REQUEST_TIME'] > 600) {
// session timed out, last request is longer than 10 minutes ago
unset($_SESSION);
session_destroy();
header("location:userlogin.php");
}
} else {
$_SESSION['LAST_REQUEST_TIME'] = time();
}
if($_SESSION['username']=="");
?>
Answer
Solution:
I am not sure that this compiles well. Because there are a couple of problems.
Be careful with this line of code:
This means that
true
part of thisif
statement finishes at semicolon.Second thing is that your
else
part is never executed but printed as regular HTML.I would write it like this:
And I believe that is what you intended to to with closing
<?php
tag.Also for readability I suggest you to do just this:
So you don't even need else part, because as soon as header is set, he will be redirected.
Answer
Solution:
Because your
is outside of
<?php ?>
Try This: