为每篇文章都在用户那加个COOKIE代表已查看过..合理吗?
最近在做文章系其中一功能,就是统计当前文章的查看次数(流量)
我的文章地址是 news.php?id=123
网上找到个方法
<br />$gid = $_GET["id];<br />if( !isset($_COOKIE["user"]) ){ <br /> setcookie("user","newGuest",time()+3600); <br />}else { <br /> setcookie("user","oldGuest"); <br />} <br /><br />if ( $_COOKIE["user"] != "oldGuest") {<br /> $hits_now = $row["hits"]+1;<br /> $pdo->exec("UPDATE `gamedb_game` SET `hits`='$hits_now' WHERE `id` = '$gid'"); <br />}
<br />$gid = $_GET["id];<br />if( !isset($_COOKIE["user"]) ){ <br /> setcookie("user","newGuest",time()+3600); <br />}else { <br /> setcookie("user","oldGuest_$gid"); <br />} <br /><br />if ( $_COOKIE["user"] != "oldGuest_$gid") {<br /> $hits_now = $row["hits"]+1;<br /> $pdo->exec("UPDATE `gamedb_game` SET `hits`='$hits_now' WHERE `id` = '$gid'"); <br />}