Jump to content

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


MIR1999

Recommended Posts

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/xhtml1/DTD/xhtml1-transitional.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!!
Link to comment
Share on other sites

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 [b]<?php[/b] tag also are you using notepad? If you are using notepade make sure you save file encoding to [b]ANSI[/b] and not [i]UFT-8[/i] or anything else otherwise somehidden chars get added to your file and so your get the headers already sent error message.
Link to comment
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.