Pag wrote:
Hi, I am having a serious problem on my site. It was working fine
until a day ago, when it simply freezes. After i made a few checks i
realized it loops on this code. I tried everything but i cant understand
why and i am going crazy trying to figure it out!
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?
oh, this code is right at the top of my main page.
Thanks!
###########################################
<?
if ($_COOKIE['pvisita'] == '1') {
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: ".$_COOKIE['pvisita']);
die; // or exit; = same thing
}else{
print ("não há registos");
break;
}
}
?>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php