Jump to content

header not redirecting


Timinator2000

Recommended Posts

Ok, I am having a hard time with the header function.. if you look at the script below, both the 2 first header functions work no problem upon given cirumstances.. but as soon as I add the last header function, the first header function does not work.. it always reverts to the last header..  what am i doing wrong?

 

Thanks everyone.

 

CODE:

 

<?

 

//------------------------------------------------------------------------------------------------------------------

// VARIABLE DECLARATION..

$username = $_GET['user'];

$password = $_GET['password'];

$Button = $_GET['Button'];

 

//------------------------------------------------------------------------------------------------------------------

 

// FUNCTION LOGIN INTO LOGIN DATABASE

 

function readdata() {

...deleted for posting purposes..}

//------------------------------------------------------------------------------------------------------------------

if ($Button == "Cancel"){

@header("Location: http://www.xxx.com/Mainview.php?selected=poker");

}

if ($Button == "Submit"){

!readdata();

$query="SELECT * FROM `login`";

$result=mysql_query($query) or die("Query failed: $query\nError: " . mysql_error());

$num_entries=mysql_numrows($result);

mysql_close();

$i=0;

while ($i < $num_entries) {

$sqluser=mysql_result($result,$i,'user');

$sqlpass=mysql_result($result,$i,'pass');

if ($username == $sqluser && $password == $sqlpass) {

@header("Location: http://www.xxx.com/test2.php");

}

$i++;

}

}

@header("Location: http://www.xxx.com/signin.php?flag=invalid");

 

 

?>

Link to comment
https://forums.phpfreaks.com/topic/77465-header-not-redirecting/
Share on other sites

You're welcome :)

And in the future, maybe consider using if, elseif, else if you want to do something if two conditions aren't met.

 

<?php
if (first condition) {
//do something if first condition is met;
} elseif (second condition) {
//do something if first condition isn't met, but the second is;
} else {
//do something if none of the conditions were met;
}
?>

 

But it is always a good idea to exit your script after a header redirect.

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.