Forum Moderators: coopster

Message Too Old, No Replies

i can't figure out what's wrong

         

MrGecko

7:32 pm on May 1, 2007 (gmt 0)

10+ Year Member



i receive this message when i try to set a cookie

Warning: Cannot modify header information - headers already sent by (output started at /Web/Coleman Family/index.php:2) in /Web/Coleman Family/index.php on line 33

here is my source code
<html><head></head>
<body>
<?
$url = $_SERVER['PHP_SELF'];
$p = isset($_REQUEST['p'])? trim($_REQUEST['p']) : "";
switch ($p) {
case "login":
?>
<center>
<form action="<?=$url?>" method="post">
<input name="p" type="hidden" value="loginc">
<table width="300" border="1">
<tr>
<td width="112" align="right">Username:</td>
<td width="172"><input type="text" name="user"></td>
</tr>
<tr>
<td align="right">Password:</td>
<td><input type="password" name="pass"></td>
</tr>
<tr>
<td align="left">
<input type="submit" name="Submit" value="Login">
</td>
<td align="right">
<input type="reset" name="Reset" value="Reset">
</td>
</tr>
</table>
</form>
</center>
<?
break;
case "loginc":
$pass = isset($_REQUEST['pass'])? trim($_REQUEST['pass']) : "";
$user = isset($_REQUEST['user'])? trim($_REQUEST['user']) : "";
if (strtoupper($user) == "USER" & strtoupper($pass) == "PASS") {
setcookie("121", "1155432", time()+12);
echo "<center><b>Please Wait Loging In</b></center>";
} else echo "<meta http-equiv=\"refresh\" content=\"1; url=$url?p=login\"><center><b>Wong Username or Password</b></center>";
break;
case "ctl":
if ($_COOKIE["121"]!= "1155432") {
echo "<center><b>Your are not login <a href=\"?p=login\">Please Login</a></b></center>";
exit();
}
?>
<a href="<?=$url?>?p=add">Add Album</a>:<a href="<?=$url?>?p=out">Logout</a>

<?
break;
}
?>
</body>
</html>

please help

DanA

7:37 pm on May 1, 2007 (gmt 0)

10+ Year Member



Set the cookie before sending any html to the browser.

MrGecko

8:05 pm on May 1, 2007 (gmt 0)

10+ Year Member



Thanks it works now