joecooper Posted June 4, 2006 Share Posted June 4, 2006 [code]<?phpsession_start(); //start the sessioninclude("db.php");$username=$_POST['username']; //Get the username the user has entered$password=$_POST['password']; //Get the password the user has entered$password=md5($password); //turn the password they entered into md5 to compare with the DB$loginname=$_SESSION['username']; //set the global varible for login name to use else where with the script.//check to see if logged in allreadyif (isset($_SESSION['loggedin'])){ //if allready logged in, push them onto the members area! header("Location : /members/index.php");//if they arent logged in allready then log them in!}?>[/code]It just loads the page and does nothing, when it should redirect the user to that page Quote Link to comment https://forums.phpfreaks.com/topic/11193-header-not-redirecting/ Share on other sites More sharing options...
redarrow Posted June 4, 2006 Share Posted June 4, 2006 [!--quoteo(post=380041:date=Jun 4 2006, 09:47 PM:name=joecooper)--][div class=\'quotetop\']QUOTE(joecooper @ Jun 4 2006, 09:47 PM) [snapback]380041[/snapback][/div][div class=\'quotemain\'][!--quotec--][code]<?phpsession_start(); //start the sessioninclude("db.php");$username=$_POST['username']; //Get the username the user has entered$password=$_POST['password']; //Get the password the user has entered$password=md5($password); //turn the password they entered into md5 to compare with the DB$loginname=$_SESSION['username']; //set the global varible for login name to use else where with the script.//check to see if logged in allreadyif (isset($_SESSION['loggedin'])){ //if allready logged in, push them onto the members area! header("Location : /members/index.php");//if they arent logged in allready then log them in!}?>[/code]It just loads the page and does nothing, when it should redirect the user to that page[/quote]try this no gap :[code]header("Location: /members/index.php");[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11193-header-not-redirecting/#findComment-41868 Share on other sites More sharing options...
wildteen88 Posted June 5, 2006 Share Posted June 5, 2006 [!--quoteo(post=380041:date=Jun 4 2006, 10:47 PM:name=joecooper)--][div class=\'quotetop\']QUOTE(joecooper @ Jun 4 2006, 10:47 PM) [snapback]380041[/snapback][/div][div class=\'quotemain\'][!--quotec--][code]<?phpsession_start(); //start the sessioninclude("db.php");$username=$_POST['username']; //Get the username the user has entered$password=$_POST['password']; //Get the password the user has entered$password=md5($password); //turn the password they entered into md5 to compare with the DB$loginname=$_SESSION['username']; //set the global varible for login name to use else where with the script.//check to see if logged in allreadyif (isset($_SESSION['loggedin'])){ //if allready logged in, push them onto the members area! header("Location : /members/index.php");//if they arent logged in allready then log them in!}?>[/code]It just loads the page and does nothing, when it should redirect the user to that page[/quote]You are checking whether the session variable, [b]loggedIn[/b] is set. But nowhere in the code you are setting the loggedIn session variable. Therefore your header redirect will not be excuted as your if statement is returning false in code below:[code]//check to see if logged in allreadyif (isset($_SESSION['loggedin'])){ //if allready logged in, push them onto the members area! header("Location : /members/index.php");//if they arent logged in allready then log them in!}[/code]In order for your if statement to return true and therefore execut the header redirect you need to create $_SESSION['loggedIn'] session variable. Like so:[code]$loginname=$_SESSION['username']; //set the global varible for login name to use else where with the script.$_SESSION['loggedIn'] = true; //create logged in session[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11193-header-not-redirecting/#findComment-41977 Share on other sites More sharing options...
joecooper Posted June 5, 2006 Author Share Posted June 5, 2006 no, i have set the varible on another page. i know what i am doing. plus if i stick an echo instead, it displays that echo, nothing wrong with the IF statement.you should know that you can set session varibles on any page and they will work with other pages Quote Link to comment https://forums.phpfreaks.com/topic/11193-header-not-redirecting/#findComment-42231 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.