Jump to content


Photo

Header/Session snag - have read threads above but still stuck


  • Please log in to reply
1 reply to this topic

#1 MIR1999

MIR1999
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 14 March 2006 - 12:30 AM

Here are the error messages i get when i try to implement my session:

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at c:\inetpub\wwwroot\login.php:1) in c:\inetpub\wwwroot\login.php on line 2

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at c:\inetpub\wwwroot\login.php:1) in c:\inetpub\wwwroot\login.php on line 2

wanted to redirect you but i could not do it!

Here is the code i have:

<?php
session_start();
//Start the session, register the values and redirect.
$_SESSION['first_name'] = $row[1];
$_SESSION['user_id'] = $row[0];
if(!headers_sent()){
header("Location:http://localhost/logged_in.php");
exit();
}else{
echo'wanted to redirect you but i could not do it!';
}
if(isset($_POST['login'])){
$u = $_POST['Login_email'];
$p = $_POST['Password'];
//Connect to db.
require_once ('../mysql_connect.php');
$query = "SELECT user_id, first_name FROM users WHERE email='$u' AND password='$p'";
$result=@mysql_query($query);
$row=mysql_fetch_array($result,MYSQL_NUM);

if($row){//A match was made


}else{//No match was made
echo '<p>The email and password entered do not match those on file.</p>';
}
mysql_close();

}else{
?>
<!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR...nsitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="content-type"content="text/html;charset=encoding"/>
<title>Login</title>
<script type="text/javascript" language="Javascript">
<!--//Validate the textfields

function CheckLogData() {
var problem2 = 'No';
if (document.login.Login_Name.value.length<=0) {
alert ("Enter your UserName.");
document.login.Login_Name.value = "*** UserName";
document.login.Login_Name.focus();
problem2 = 'Yes';
}
if (document.login.Password.value.length<=0) {
alert ("Enter your Password.");
document.login.Password.value = "*** Password";
document.login.Password.focus();
problem2 = 'Yes';
}
if (problem2 == 'No') {
return true;
} else {
return false;

}
}
//-->
</script>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" onsubmit="return CheckLogData()">
<fieldset><legend> Enter your email address and password in the boxes below:</legend>
<p align="left"><b>Email :</b> <input type="text" name="Login_email" size="30"></p>
<p align="left"><b>Password :</b><input type="text" name="Password" size="20"></p>
<p align="left"><input type="submit" name="login" value="LOGIN"></p>
</form>

</body>
<?php

}
?>
</html>

Any ideas why its gone pear shaped? I accept that the code is probably completely wrong. Let me have it, don't hold back!!

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 14 March 2006 - 10:18 AM

The error message is telling me that you have something being outputted to browser on line 1 in login.php

Now do you have any spaces before the <?php tag also are you using notepad? If you are using notepade make sure you save file encoding to ANSI and not UFT-8 or anything else otherwise somehidden chars get added to your file and so your get the headers already sent error message.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users