haruncpi Posted July 11, 2012 Share Posted July 11, 2012 in my site i made a login system. i create session for special pages. that pages can see only registered member. in my login system when a user login succesfully it shows a succeslog.php page else wrnglog.php page. but after login succesfully user don't get that page which page he/she wanted to see before login. my question is after login successfully how to i will redirect a user on that page which page he/she wanted to visit before login? would any body help me please? Link to comment Share on other sites More sharing options...
birbal Posted July 11, 2012 Share Posted July 11, 2012 instant redirectheader("location:http://yourpage.com") timed redirect after 5 seconds to specified url. works like meta redirectheader("refresh:5;url=http://yourpage.com"); http://php.net/header Link to comment Share on other sites More sharing options...
haruncpi Posted July 11, 2012 Author Share Posted July 11, 2012 instant redirectheader("location:http://yourpage.com") timed redirect after 5 seconds to specified url. works like meta redirectheader("refresh:5;url=http://yourpage.com"); http://php.net/header in the site there are a lot of pages. so i can not fixed url because i don't know user which page wanted to visit.? at a time indivitual user might be visit indivitual page. so i have use a function which redirect user Link to comment Share on other sites More sharing options...
birbal Posted July 11, 2012 Share Posted July 11, 2012 You can use $_SERVER['HTTP_REFERER'] (it have the page name from where the user came from) in the place of url in the header()Remember to set a default url location to fallback incase $_SERVER['HTTP_REFERER'] is not a valid url 1 Link to comment Share on other sites More sharing options...
justsomeguy Posted July 11, 2012 Share Posted July 11, 2012 One way would be to save the page in the session before you redirect them to log in. Once they log in, you check to see if there's a page saved in the session and redirect them to that page instead of the default redirection. You can use $_SERVER['REQUEST_URI'] as the page to redirect back to after they login. So, on your protected page you check if they're logged in. If they aren't logged in, you save $_SERVER['REQUEST_URI'] in the session, like in $_SESSION['login_redirect'] for example. After you save that to the session, you redirect them to the login page. Once they successfully log in, you check if $_SESSION['login_redirect'] is set. If it is, redirect to that page, or else redirect to where you do now. Link to comment Share on other sites More sharing options...
haruncpi Posted July 11, 2012 Author Share Posted July 11, 2012 Will i write like this?if login successfully header("location:$_SERVER['HTTP_REFERER']"); Link to comment Share on other sites More sharing options...
haruncpi Posted July 11, 2012 Author Share Posted July 11, 2012 (edited) What i have to do in the if true part for redirecting a user that place where he/she wanted to visit before login? if($count==1){// store session data$row = mysql_fetch_array($result);//echo $row['name'];$_SESSION['harun']= $row['email'] ;//print $row['name'] . "Thanks, Redirecting";header( "location:member_login_success.php");}else {//echo "Wrong Username or Password";//print "Wrong Username or Password";header("location:member_login_wrong.php"); Edited July 11, 2012 by haruncpi Link to comment Share on other sites More sharing options...
birbal Posted July 11, 2012 Share Posted July 11, 2012 (edited) if(!empty($_SERVER['HTTP_REFERER'])) // <=you can add validation of the referer. REMEMBER this header is spoofableheader( "location:{$_SERVER['HTTP_REFERER']}");elseheader( "location:{$_SERVER['REQUEST_URI']}"); } Edited July 11, 2012 by birbal Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now