Jump to content


Photo

header not redirecting


  • Please log in to reply
3 replies to this topic

#1 joecooper

joecooper
  • Members
  • PipPipPip
  • Advanced Member
  • 358 posts

Posted 04 June 2006 - 09:47 PM

<?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!
}
?>

It just loads the page and does nothing, when it should redirect the user to that page
Signature:
[/a]
[a href="http://www.planet-so...=1999&lngWId=8" target="_blank"]EzLogin 1.0[/a]
[a href="http://www.essexracers.com" target="_blank"]Essexracers.com[/a]
Msn Messenger: joe@joeyjoe.co.uk

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 04 June 2006 - 09:57 PM

[!--quoteo(post=380041:date=Jun 4 2006, 09:47 PM:name=joecooper)--][div class=\'quotetop\']QUOTE(joecooper @ Jun 4 2006, 09:47 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
<?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!
}
?>

It just loads the page and does nothing, when it should redirect the user to that page
[/quote]

try this no gap :
header("Location: /members/index.php");

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 05 June 2006 - 10:17 AM

[!--quoteo(post=380041:date=Jun 4 2006, 10:47 PM:name=joecooper)--][div class=\'quotetop\']QUOTE(joecooper @ Jun 4 2006, 10:47 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
<?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!
}
?>

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, loggedIn 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:
//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!
}
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:
$loginname=$_SESSION['username']; //set the global varible for login name to use else where with the script.
$_SESSION['loggedIn'] = true; //create logged in session


#4 joecooper

joecooper
  • Members
  • PipPipPip
  • Advanced Member
  • 358 posts

Posted 05 June 2006 - 11:46 PM

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
Signature:
[/a]
[a href="http://www.planet-so...=1999&lngWId=8" target="_blank"]EzLogin 1.0[/a]
[a href="http://www.essexracers.com" target="_blank"]Essexracers.com[/a]
Msn Messenger: joe@joeyjoe.co.uk




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users