检查同一用户是否访问过网站!?!怎么样? [英] Check if same User visited web site!?! How?

查看:60
本文介绍了检查同一用户是否访问过网站!?!怎么样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查访问我网站的用户是否是半小时前来的用户?

How can I check if User which came to my web site, is same User which came half hour before?

推荐答案

首先,您需要使用他的IP地址,然后检查您的数据库中是否保存了IP,可以说是过去24小时,如果您使用的是同一个用户,如果您没有,则其他人或他的IP已更改! OFC。你可以观看更多的东西,但这是一个基本的。

First you need to use his IP Address and then check if you have that IP saved in your database in lets say about last 24 hours and if you do than its the same user and if you dont then its someone else or his IP changed! ofc. there are much more things you can watch on but this is a basic.

这里有一个例子(你只需要制作数据库):

ok here is an example (you just need to make database):

$ip=$_SERVER['REMOTE_ADDR'];
$cook=$_COOKIE["visitor"];
$checkit = mysql_query("SELECT * FROM pagevisitors WHERE date_format(date_added,'%Y%m%d%H')>date_format(adddate(now(), interval - 24 hour),'%Y%m%d%H') AND visitor_IP='".$ip."' AND visitor_Cookie='".$cook."' ORDER BY id DESC limit 1");
$checked = mysql_fetch_array($checkit);
if($checked){
  //same visitor
}
else{
  // new visitor & add him to your database & a cookie
  // make random string for him
  $hisString=genRandomString();
  setcookie("visitor", $hisString, time()+86400);
  mysql_query("INSERT INTO pagevisitors (visitor_IP, date_added,visitor_Cookie) VALUES  ('".$ip."', now(),'".$hisString."')");
}

// function for random string
function genRandomString(){
    $length = 25;
    $characters = "0123456789abcdefghijklmnopqrstuvwxyz";
    $string = '';    
    for ($p = 0; $p < $length; $p++) {
        $string .= $characters[mt_rand(0, strlen($characters))];
    }
    return $string;
}

在数据库中,字段id会自动增加! :)
这应该有用......没有测试过它!

and in database the field "id" make auto increase! :) this should work... didnt tested it!

这篇关于检查同一用户是否访问过网站!?!怎么样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆