Jump to content

Header issue...


mhoctober

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>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.