Closed Thread Icon

Topic awaiting preservation: Trouble with Cookies (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=13003" title="Pages that link to Topic awaiting preservation: Trouble with Cookies (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Trouble with Cookies <span class="small">(Page 1 of 1)</span>\

 
marf
Bipolar (III) Inmate

From: Canada
Insane since: Oct 2001

posted posted 11-26-2003 04:08

Ok I am making a basic counter. IT puts a cookie on the persons computer and adds their number to a total. Then writes to a file. When the user comes back, if they have the cookie on their computer, then they won't be counted again.

code:
<?php
setcookie("visited",1,time()+3600);
?>
<html>
<head>
<title> Test </test>
</head>
<body>
//IF they have visited site before cookies value will be 1
if ($HTTP_COOKIE_VARS["visited"] == 2){

//CODE TO OPEN FILE HERE and DISPLAY THE NUMBER


//Otherwise they havn't visited the site, therefore their cookie is only equal to one
} else {

$num = $HTTP_COOKIE_VARS["visited"] + 1; //adds one to 1, making it 2.
setcookie("visited",$num,time()+3600); //set the cookie with a value of 2

//Now it opens the text file with the number in it, adds one to the total number and prints the amount, then saves the file with the new values.

}
?>

</body>
</html>



I'm getting an error on line 123

which is: setcookie("visited",$num,time()+3600); //set the cookie with a value of 2

I can't figure out whats wrong

PLZ help

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 11-26-2003 04:41

You can't output anything before calling the setcookie function. besides the html you have outputting can't even have one space before your php opening tag.



.:[ Never resist a perfect moment ]:.

« BackwardsOnwards »

Show Forum Drop Down Menu