warning setcookie

From: Date: Thu, 11 Mar 2004 15:26:54 +0000
Subject: warning setcookie
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-26295@lists.php.net to get a copy of this message
hello I 'm a begginer in Php and I have a little problem with the example on http://fr2.php.net/manual/fr/function.setcookie.php (I put it a the end of my mail) When I execute it I have 2 warning message : >>>>Warning: Cannot add header information - headers already sent by (output started at /var/www/html/cookie.php:2) in /var/www/html/cookie.php on line 27 >>>Warning: Cannot add header information - headers already sent by (output started at /var/www/html/cookie.php:2) in /var/www/html/cookie.php on line 28 But the script is ok becasuse I have this message too : >>>>Authentication was successful! The cookies have been sent! >>>>You'll be redirected in 5 seconde I think that I send header before or after something wrong but what ? I didn't send header message .I changed one or two thing like how getting the value of $login for example but I don't think that it's bad.(but maybe I'm wrong ;( somedy could help me ? thank you very much JS. ps : the script is cookie.php cat cookie.php <?php function checkAuth($userToCheck, $passToCheck) { $user = "foo"; $pass = "bar"; $encodedPass = md5($pass); if ($userToCheck == $user && $passToCheck == $encodedPass) { $check = TRUE; } else { $check = FALSE; } return $check; } if (isset($_GET['relogin'])) { setcookie ('cuser', "",time()-3600, '/','yourhost.com'); setcookie ('cpass', "",time()-3600, '/','yourhost.com'); } if (isset($_GET['login'])) { $password = md5($_POST['formPass']); $username = $_POST['formUser']; if (checkAuth($username, $password)) { setcookie ('cuser', $username,time()+3600, '/','http://localhost'); setcookie ('cpass', $password,time()+3600, '/','http://localhost'); $msg = "Authentication was successful! The cookies have been sent!"; }else{ $msg = "Authentication error!"; } } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <?php if (isset($_GET['login'])) { echo("<meta http-equiv='refresh' content='5;url=cookie.php'>"); } ?> <title>Test Cookie</title> </head> <body> <?php if (isset($COOKIE['cuser']) && !isset($_GET['relogin'])) { if (checkAuth($COOKIE['cuser'], $COOKIE['cpass'])) { echo("<p>Hello $cuser!</p>" . "<p>Your password (md5 encrypted) is: ".$COOKIE['cpass']."</p>" . "<p><a href='cookie.php?relogin=1'>Delete cookies and force login<a></p>"); } else { echo("<p>Authentication error from cookies values</p>" . "<p><a href='cookie.php?relogin=1'>Delete cookies and force login<a></p>"); } } else { if (!isset($_GET['login']) || isset($_GET['relogin'])) { ?> <form action="cookie.php?login=1" method="POST"> <p>User: <input type="text" name="formUser"></p> <p>Pass: <input type="password" name="formPass"></p> <p><input type="submit" name="submit" value="Log In"></p> </form> <?php } elseif (isset($_GET['login'])) { echo("<p>$msg</p>" . "<p>You'll be redirected in 5 seconds!</p>"); } } ?> </body> </html> ******ADSL Tiscali, le Haut débit au meilleur prix ****** Avec Tiscali, profitez de l'ADSL au meilleur prix partout en France ! Pour profiter de cette offre exceptionnelle, cliquez ici : http://register.tiscali.fr/adsl Sous réserve d'éligibilité à l'ADSL.

« previous php.pear.dev (#26295) next »