>       This code is supposed to write a 24h cookie at first visit, and
then
> checks for it at every refresh, if the cookie doesnt exist, it
increases a
> counter on the DB. Simple, right? Then why did it stop working out of
the
> blue? It loops on the refresh, keeps thinking the cookie is not
active, so
> it keeps adding +1 to the counter. What am i doing wrong? How can i
fix
> it?
> <?
> if ($pvisita == '1') {

Try if($_COOKIE['pvisita'] == 1) instead...

> break;
> } else {
> 
> include ('databaseinfo.txt');
> $ligacao=mysql_connect($h, $u, $p) or die("Erro ao aceder a MySQL");
> @mysql_select_db($DBname) or die("Unable to select database " .
$DBname);
> $resultado = mysql_query ("select * from counttable where id='0'");
> 
> if ($resultado) {
> $registo = mysql_fetch_array($resultado);
> $id = $registo["ID"];
> $contador = $registo["contador"];
> $contador = $contador + 1;
> $resultado2 = mysql_query ("update counttable set contador='$contador'
> where id='0'");
> setcookie("pvisita", "1", time() + 86400);
> header("Location: $PHP_SELF");
> 
> }else{
> print ("não há registos");
> break;
> }

Also, for the rest of that, it'd be easier to just issue one query such
as:

Update countable set contador = contador + 1 where id = 0

---John W. Holmes...

PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to