mhoctober Posted August 18, 2006 Share Posted August 18, 2006 Experts...I want to check for the existence of a cookie, and if its not set, set it. I am getting this warning as I load my code in a browser...any ideas??Warning: Cannot modify header information - headers already sent by (output started at /home2/seeasale/public_html/updatestats.php:4) in /home2/seeasale/public_html/updatestats.php on line 14Page Loads : 15 Here is the code...<html><body><?phpif (isset($_COOKIE["ck"])){//echo "Cookie Set";} Else{//echo "Cookie Not Set, Setting Cookie and Updating Counter";//Line 14 follows...setcookie ("ckBeenHere", time()+43200); // will expire in 12 hours $i=0;$pageVisited = $_SERVER['PHP_SELF'];$dbh=mysql_connect ("localhost", "****", "****") or die ('I cannot connect to the database because: ' . mysql_error());mysql_select_db ("seeasale_db"); $query="SELECT * FROM tblCounter where fldURL='$pageVisited'";$result=mysql_query($query)or die (mysql_error()); $num=mysql_numrows($result);echo;if ($num==0) // page has never been visited before by anyone!{$query = "INSERT INTO tblCounter(fldURL,fldCount) VALUES ('$pageVisited',1)";mysql_query($query) or die('There is a problem: ' .mysql_error()); }else{$upCounterByOne=mysql_result($result,$i,"fldCount")+1;$query = "UPDATE tblCounter SET fldCount = '$upCounterByOne'WHERE fldURL='$pageVisited'"; $result=mysql_query($query)or die (mysql_error()); echo "<center>";Echo "Page Loads : ";echo $upCounterByOne; }}?></body></html> Link to comment https://forums.phpfreaks.com/topic/17991-header-issue/ Share on other sites More sharing options...
corbin Posted August 18, 2006 Share Posted August 18, 2006 There cant be anything before headers.. So move the html and body tags till after the cookie stuff :D Link to comment https://forums.phpfreaks.com/topic/17991-header-issue/#findComment-77033 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.