How can I check if User which came to my web site, is same User which came half hour before?
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(affffdate(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;
}
and in database the field "id" make auto increase! :) this should work... didnt tested it!