Jump to content

Archived

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

joecooper

header not redirecting

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

Share this post


Link to post
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]

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

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.