Page 1 of 1

my headers erro why pls can anyone help ,???

Posted: Thu Oct 12, 2006 6:53 am
by infophp
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


here my code i dont know there is an error HEADER

Code: Select all

<?PHP 

if (!isset($username) || !isset($password)){
header( "Location: http://www.yourdomain/login.htm" );//-->>>>>>>>>>>>>>>>>>>>>> THIS IS THE ERROR 

//SAYING THAT ---- >>>>Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\login\login.php:9) in C:\wamp\www\login\login.php on line 13------- WHATS THE PROBLEM PLS?????????/         
 

}
//check that the form fields are not empty, and redirect back to the login page if they are 
elseif (empty($username) || empty($password)) { 
header( "Location: http://www.yourdomain.com/login.htm" );  
} 
else{ 

//convert the field values to simple variables 

//add slashes to the username and md5() the password 
$user = addslashes($_POST['username']); 
$pass = md5($_POST['password']); 


//set the database connection variables 

$dbHost = "localhost"; 
$dbUser = "yourUsername"; 
$dbPass = "YourPassword"; 
$dbDatabase = "yourDB"; 

//connet to the database 

$db = mysql_connect("$dbHost", "$dbUser", "$dbPass") or die ("Error connecting to database."); 

mysql_select_db("$dbDatabase", $db) or die ("Couldn't select the database."); 

$result=mysql_query("select * from users where username='$user' AND password='$pass'", $db); 

//check that at least one row was returned 

$rowCheck = mysql_num_rows($result); 
if($rowCheck > 0){ 
while($row = mysql_fetch_array($result)){ 

  //start the session and register a variable 

  session_start(); 
  session_register('username'); 

  //successful login code will go here... 
  echo 'Success!'; 

  //we will redirect the user to another page where we will make sure they're logged in 
  header( "Location: checkLogin.php" ); 

  } 

  } 
  else { 

  //if nothing is returned by the query, unsuccessful login code goes here... 

  echo 'Incorrect login name or password. Please try again.'; 
  } 
  } 
?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Thu Oct 12, 2006 7:00 am
by feyd
Searching for that phrase should have pointed to the mountain of times we've answered it.

viewtopic.php?t=1157