Redirecting to a page after login in PHP






4.38/5 (7 votes)
Redirecting to a page after login in PHP
It's sometime required to redirect to a page if some
conditions are met. You may include an auth.php page in any
page. This auth.php handles login and if login username
and password are matched, then the user will be redirected
to the member home page using 'header'. The code is shown below:
if($password == $passwordtext)
{
$_SESSION["userid1"] = $id1;
header("Location: https://mysite.com
/members/index.php"); // redirects
}
else
{
unset($_SESSION["userid1"]);
$_SESSION["msg"] = "<li>Login Info - Username
/Password: Incorrect Combination try again</li>";
}