Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.