...

View Full Version : Any effective hit counter without cookie?



abduraooft
08-07-2007, 04:19 PM
Hi friends,

I want to setup a website hit counter to record the hits of users.

My intention is to..
1) Get the IP address of client.
2) Check whether it is a continuation of his previous visit.
3) If there is a considerable delay b/w his previous hit, increment counter; else make delay to NULL

These steps are to be carried out in all pages.

Everything is OK, except in Step 1 ;) . It fails in the case of a set of users who share a common IP to connect to Internet. ie. If some of them are simultaneously visiting the site, then I can't keep the delay value as expected.

Any other idea?
(Worked around $_SERVER['HTTP_X_FORWARDED_FOR'], but no o/p for that line.)

Thanks n regards,
art

mic2100
08-07-2007, 05:50 PM
hi,

one question...

y no cookies???

This would be so much easier using cookies!!!

Thanks

abduraooft
08-07-2007, 06:15 PM
I feel it's not good to export something to visitor's system(I may be a wrong..).
However if no other way, I'll compromise ;) .

BW What's the exact purpose of HTTP_X_FORWARDED_FOR? Is it useful anyway?

Thanks,
art.

rafiki
08-07-2007, 06:55 PM
I feel it's not good to export something to visitor's system(I may be a wrong..).
However if no other way, I'll compromise ;) .

BW What's the exact purpose of HTTP_X_FORWARDED_FOR? Is it useful anyway?

Thanks,
art.

it returns the users IP address but apparantly it can be easily faked.

CFMaBiSmAd
08-07-2007, 06:59 PM
HTTP_X_FORWARDED_FOR is an optional header that is provided by non-anonymous proxy servers that indicates the IP address they received the request from (this can be an array of IP addresses if the request was handled by a string of proxies.) Anonymous proxy servers (those that don't want you to know they are proxies) either don't send this header or set it to their own IP address to make you think the request came from them. An anonymous proxy could also set it to a different value on each request, even if those requests all came from the same IP, to make you think each request is from a different address.

If HTTP_X_FORWARDED_FOR is present, you can use it to help distinguish between different requests made through one proxy server (same REMOTE_ADDR) but you cannot really rely on it for any mission critical application (which is true of all the HTTP_ headers, they are all optional and they can all be faked.)

rafiki
08-07-2007, 07:03 PM
HTTP_X_FORWARDED_FOR is an optional header that is provided by non-anonymous proxy servers that indicates the IP address they received the request from (this can be an array of IP addresses if the request was handled by a string of proxies.) Anonymous proxy servers (those that don't want you to know they are proxies) either don't send this header or set it to their own IP address to make you think the request came from them. An anonymous proxy could also set it to a different value on each request, even if those requests all came from the same IP, to make you think each request is from a different address.

If HTTP_X_FORWARDED_FOR is present, you can use it to help distinguish between different requests made through one proxy server (same REMOTE_ADDR) but you cannot really rely on it for any mission critical application (which is true of all the HTTP_ headers, they are all optional and they can all be faked.)
meh its a little more detailled than mine but couldnt find out much about it on the php website (mayb ei should look harder next time)

croatiankid
08-07-2007, 07:42 PM
Well, in your about/terms of use/whatever page, you can mention that they've got a cookie from you for statistical analysis or whatever.

matak
08-07-2007, 08:55 PM
You can get easily get hit of this link

<a href="mysite/mypage.html">MyPage</a>

Does any one of you know how to get this hit

<a href="?mysit=mypage.html">MyPage</a>

If anyone gives me a hint, or complete solution, i'll post flat file Hit's script, which i use only for visitors script...

abduraooft
08-08-2007, 09:13 AM
it returns the users IP address but apparantly it can be easily faked.

Thanks, but I get nothing when I used

echo $_SERVER['HTTP_X_FORWARDED_FOR'];

regards,
art

mic2100
08-08-2007, 10:03 AM
hi matak,

you can use the following php code at the top of the page to navigate to the link...



<?

if(isset($_GET['mysit'])):

//in here you can access the page selected by checking the variable $_GET['mysit']
//if you then want to log this, make your db connection here.

/*

other processing code here

*/

//please make sure that this HEADER is at the bottom of whatever code you place in this if statement
header('Location: '.$_GET['mysit']);

endif;

?>


now if you have some code for an hit counter i would also really like it.

Thanks...

Mic

matak
08-08-2007, 10:53 AM
Feel free to comment on this visitors script..


function getVisits($variable) {

$visits = array();

$date = date('Y-m-d');

if ($handle = opendir('base/stats/')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
array_push($visits, $file);
}
}
closedir($handle);
}
$key = array_search($date.$variable, $visits);

if ($key !== FALSE) {

echo "Visits: ".count($visits);

}
elseif ($key === FALSE){
$file = fopen("baza/stats/".$date.$variable, 'a');
fwrite($file, $variable);
fclose($file);

getVisits($variable);
}
}

Anway this script writes IP adresses and dates in file, so that tomorow you can still get visits from same IP's :p

mic2100
08-08-2007, 11:20 AM
thanks,
but still no one as really answered the original post, is there a way to log user visits without using a cookie? I didn't ask this n i think using them is ok since that most users are now beyond to point of paranoia about them.

meth
08-08-2007, 03:42 PM
If by user, you're referring to a particular user logged on to a particular computer and if you are implying a solution along as simple lines as a cookie, then no, there isn't.

Perhaps you may want to check out a few php tracking systems:

phpOpenTracker (http://www.phpopentracker.de/) and phpSniff (http://phpsniff.sourceforge.net/)

abduraooft
08-09-2007, 09:30 AM
If by user, you're referring to a particular user logged on to a particular computer and if you are implying a solution along as simple lines as a cookie, then no, there isn't.



Well, I don't think cookie is so effective. What happens when someone block/clear cookie from his system?

Anyway, if I'm going to use cookie, I assume the following steps will work

1) Check for the value (accessed time in seconds).
2) Check DB with this value and the current IP
3) If a considerable delay, increment count.
4) Set a new cookie.

please correct me if anything wrong (I haven't used a cookie yet)

thanks
art

usik
08-09-2007, 11:41 AM
you could simply store a persons ip address and the date they last were on
and then say



$date = date("Ynj");
$query = mysql_query("SELECT date, count FROM counter WHERE ip = {$_SERVER["REMOTE_ADDR"]}");

$last_visit = mysql_fetch_array($query);

if(empty($last_visit["date"])) {
mysql_query("INSERT INTO counter (ip, date, count) VALUES ('{$_SERVER["REMOTE_ADDR"]}', '$date', '1')");
}
else if($last_visit["date"] <= $date - 10) {
$count = $last_visit["count"] + 1;
mysql_query("UPDATE counter SET date = '$date' AND count = '$count' WHERE ip = {$_SERVER["REMOTE_ADDR"]}");
}

abduraooft
08-09-2007, 12:48 PM
Hi usik,
I'm using a similar code, but it has a problem when a group of users share a common IP to connect to the Internet, and this was the only problem which I explained in the original post (ie. no way to get their IP on LAN).

anyway thanks for your post

regards,
art.


you could simply store a persons ip address and the date they last were on
and then say

usik
08-09-2007, 01:51 PM
well yes you will need to make a cookie



setcookie("counter", 1, time()+864000);


this will set a cookie that you can check is set, if it isnt than add their ip address to the database and add the counter by one. the example cookie will expire after 10 days, so they wont add 2 the counter

firepages
08-09-2007, 03:39 PM
You could use sessions which will work with or without cookies to track a user during their visit, but unless you use cookies you can not identify that user the next time they return to your site (unless you make then login etc).



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum