Click to See Complete Forum and Search --> : Cannot modify header information error


conputerguy99
09-03-2005, 09:49 PM
I'm using this php code to login users.

<?php
$name = $_POST['name'];
$pass = $_POST['pass'];
if($name == "Joan Jones" && $pass == "karen94"){setcookie("namec", "Joan");}
else {$namec = "person who is desperate enough to try and make up a valid login";}
print "Hello, $namec";
?>

Then I get this error message. Does anyone know what this means?

Warning: Cannot modify header information - headers already sent by (output started at /home/redriver/public_html/design/customers.php:10) in /home/redriver/public_html/design/customers.php on line 13

schizo
09-03-2005, 10:02 PM
Make sure you have no HTML output before your PHP code in this instance.

"Like other headers, cookies must be sent before any output from your script (this is a protocol restriction). This requires that you place calls to this function prior to any output, including <html> and <head> tags as well as any whitespace. If output exists prior to calling this function, setcookie() will fail and return FALSE."

conputerguy99
09-03-2005, 10:08 PM
Thank you so much! I've had this problem for a long time! THANK YOU!!!!!!!!!!!

schizo
09-03-2005, 10:10 PM
You're welcome. If you're using PHP 4 (or greater), you can also use output buffering to get around this problem. Additional information can be found here:
http://us2.php.net/manual/en/function.setcookie.php