Click here to Skip to main content
15,888,351 members
Articles / General Programming
Tip/Trick

Redirecting to a page after login in PHP

Rate me:
Please Sign up or sign in to vote.
4.38/5 (7 votes)
21 Dec 2010CPOL 101.7K   10   7
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)


Written By
Software Developer self
Bangladesh Bangladesh
joomla,dnn, wordpress extensions and website developer -
http://techhelpsource.com/
http://extensions.techhelpsource.com/

Comments and Discussions

 
Questionlogging in with user type Pin
minejass9-Jul-12 16:37
minejass9-Jul-12 16:37 
Questionhttp://y2be.tk Pin
theoplay14-May-12 9:50
theoplay14-May-12 9:50 
GeneralReason for my vote of 5 Good hint! Pin
Ole Funch27-Dec-10 22:10
Ole Funch27-Dec-10 22:10 
GeneralReason for my vote of 4 Am new to PHP but the code is easy t... Pin
Sicelile27-Dec-10 9:32
Sicelile27-Dec-10 9:32 
GeneralI remember, for a script I was written, opera cached my redi... Pin
JH6427-Dec-10 6:48
JH6427-Dec-10 6:48 
General@nguyen.. did u include the page name? like header("Location... Pin
mridul samadder23-Dec-10 9:48
mridul samadder23-Dec-10 9:48 
GeneralAny help ??? header("Location: https://mysite.com"); not w... Pin
nguyenchauhuyen21-Dec-10 22:09
nguyenchauhuyen21-Dec-10 22:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.