Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / programming

Redirecting to a page after login in PHP

4.38/5 (7 votes)
21 Dec 2010CPOL 103.4K  
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:

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

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)