65.9K
CodeProject is changing. Read more.
Home

Redirecting to a page after login in PHP

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.38/5 (7 votes)

Dec 20, 2010

CPOL
viewsIcon

103382

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>";
}