Jump to content

Archived

This topic is now archived and is closed to further replies.

mhoctober

Header issue...

Recommended Posts

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 14

Page Loads : 15

Here is the code...

<html>
<body>

<?php

if (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>

Share this post


Link to post
Share on other sites
There cant be anything before headers.. So move the html and body tags till after the cookie stuff :D

Share this post


Link to post
Share on other sites

×

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.