在PHP中跟踪访问者IP /点击次数 [英] Tracking visitor IP/Clicks in PHP
问题描述
我想写一个脚本或更多像一个简单的逻辑来跟踪点击或访问。我不需要跟踪每个页面,只要他们登陆首页是我想要存储为1点击。
I am trying to write a script or more like come up with a simple logic to track clicks or visits. I don't need to track each page, just as long as they land on the homepage is where I want to store it as 1 click.
首先,它可以安全地说,IP跟踪是远远不准确,因为许多用户可以在同一个IP?
First of all, is it safe to say that tracking by IP is far from accurate because many users can be under the same IP?
目前我的逻辑,这样做是设置一个cookie客户端当他们第一次登陆首页时带有标志。在这一点上,我将更新数据库与1个unclue点击是唯一的。然后每当这个访问者访问,首页会检查该标志,如果存在,用1个原始的点击...更新数据库....等。
Currently my logic to do this is set a cookie on client side with a flag when they land on the homepage for the first time. At that point, I would update the database with 1 unqiue click as unique. Then each time this same visitor visits, the homepage would check for the flag and if it exists, update the database with 1 raw click....etc.
知道如果他们转储他们的cookie,它会丢弃的数据,但一般来说,这是怎么做?
I do know that if they dump their cookies, it would throw off the data but generally, is this how it is done?
您有更好的方法吗?
推荐答案
检索访问者的ip,它对我的统计工作正常:
Try this to retrieve the ip of the visitor, it works fine for my statistics :
function get_ip()
{
if($_SERVER){
if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
$adress = $_SERVER['HTTP_X_FORWARDED_FOR'];
elseif(isset($_SERVER['HTTP_CLIENT_IP']))
$adress = $_SERVER['HTTP_CLIENT_IP'];
else
$adress = $_SERVER['REMOTE_ADDR'];
} else {
if(getenv('HTTP_X_FORWARDED_FOR'))
$adress = getenv('HTTP_X_FORWARDED_FOR');
elseif(getenv('HTTP_CLIENT_IP'))
$adress = getenv('HTTP_CLIENT_IP');
else
$adress = getenv('REMOTE_ADDR');
}
return $adress;
}
这篇关于在PHP中跟踪访问者IP /点击次数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!