I have basic PHP code at the top of my home page to redirect the user to the login page if the user is not logged in. Before the user is redirected, loading HTML and JavaScript makes some AJAX requests for user information. Although no sensitive information is at risk, it is a waste of server resources, and I would like to prevent this.
My code is:
if(!isset($_SESSION['user_id']) || $_SESSION['user_id'] == '')
{
echo '<META HTTP-EQUIV="Refresh" Content="0; URL=/login.php">';
}
Is there a better way to redirect or prevent a page from loading further?
Jsp64 source
share