<?PHP header(location)?>?

  • Thread starter Thread starter Viper N
  • Start date Start date
V

Viper N

Guest
Why does this not redirect users to another site?

<?php


$uname=htmlspecialchars($_POST['drivername']);
$pword=htmlspecialchars($_POST['driverpassword']);

$user_name='nreddin';
$password='';
$database='rides';
$server='localhost';


$conn=mysql_connect($server,$user_name);
if(!$conn){
die('No connect:'.mysql_error());
}
else{
print"connected to server<br>";
} //good so far

$db=mysql_select_db($database, $conn);
if(!$db){
die('Database not found:'.mysql_error());
}
else{
print"connected to database<br>";

$SQL="SELECT*FROM login WHERE L1='$uname' AND L2='$pword' " ;
if(!$SQL){
die("Table not found".mysql_error());
}
else{
print("Tabvle Selected");
}

$result=mysql_query($SQL);
if(!$result){

print(mysql_error()."<br> Improper Username and/ or Password! * NOTE all Characters are CaseSensitive*");
}
else{
//print("fidskfj"); trouble shooting works this far with proper syntax closure

$num_rows=mysql_num_rows($result);
if($num_rows==1){
session_start();
$_SESSION['authenticated']="1";
if(!(header("location:http://localhost:8888/welcomepg.htm"))){
print(mysql_error());}
else{print('header');}
}
else{
$errorMessage='Invalid Login';
session_start();
$_SESSION['authenticated']='';
}

}
}
print($num_rows);
// it knows it is logged in; Session start fucking it up//
?>

The print num_rows was put there at the end just to help troubleshoot.
The whole thing is a bit messy... sorry
ANy help is appreciated...
 
a browser can't DO anything with headers except the first time it receives them and it HAS to have them before it gets the first text.

The first time you output text (print"connected to database<br>";) the browser MUST send the headers.

You should get an error message that says something in the order of "cannot send header; headers already sent". So either don't send text before you redirect, (no print, no echos) or be prepared for the redirect to fail anytime the script goes down a path that sends text.
 
Back
Top