Jump to content

header not redirecting


joecooper

Recommended Posts

[code]<?php
session_start(); //start the session
include("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 allready
if (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
Link to comment
https://forums.phpfreaks.com/topic/11193-header-not-redirecting/
Share on other sites

[!--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]<?php
session_start(); //start the session
include("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 allready
if (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]
Link to comment
https://forums.phpfreaks.com/topic/11193-header-not-redirecting/#findComment-41868
Share on other sites

[!--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]<?php
session_start(); //start the session
include("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 allready
if (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 allready
if (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]
Link to comment
https://forums.phpfreaks.com/topic/11193-header-not-redirecting/#findComment-41977
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.