![]() ![]() |
Jan 29 2009, 05:04 AM
Post
#1
|
|
|
Message Adept ![]() ![]() ![]() Group: Members Posts: 58 Joined: 2-July 04 From: ex-pat in Europe Member No.: 2,535 |
Over the Thanksgiving holiday (in 2008) a friend of mine went to Shanghai and sent me an email from her hotel using my domain address. Usually, a friend sending email to my domain address is no problem. I use my ISP email address for all commercial sites so I can separate the email.
Since my friend sent the email from her Chinese hotel, I have been getting multiple hits every day on my domain homepage from two IP ranges in two different provinces -- 124.115.0.161 (and other IPs in this range) and 58.61.164.141 (and other IPs in this range). After running a whois for the US I found that the hits are coming from Asia-Pacific. Using APNIC whois, I saw that 58.61.164.141 (58.60.0.0 - 58.63.255.255) is CHINANET Guangdong province network and 124.115.0.161 (124.114.0.0 - 124.115.255.255) is CHINANET Shanxi province. All of the hits are using the very same browser/OS configuration - Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1). Now, multiple hits from several different IP addresses do not usually have the same configuration (I keep close track for all of the Websites I design), especially when they come from different geographical regions. So, this seems like a large organization, like a government possibly. So, being sort of an activist on the topic of open access to information over the Internet, and especially in countries where access is restricted, I modified my tracking code (in PHP) to check to see if a visitor comes from one of the IP ranges that these Chinese visitors come through. I then use the HTML META HTTP-EQUIV tag to redirect to a different Website - FreeTibet.org in this case. So, in the following code, you see how to check where a visitor is coming from and what browser/OS is used, and how to use the META HTTP-EQUIV tag to redirect. Of course, you will have to write the USER data somewhere so you can read it, such as to a tracking database (I log it all into a MySQL database). CODE <?php if (isset($_SERVER['HTTP_REFERER'])) { $SERVER_REFERER = $_SERVER['HTTP_REFERER']; } else { $SERVER_REFERER = ""; } $browser=$HTTP_USER_AGENT; $ip = getenv ('REMOTE_ADDR'); $ipname = gethostbyaddr ($ip); $today = getdate(); $month = $today['month']; $mday = $today['mday']; $year = $today['year']; $login_date=gmdate('Y-m-d H:i:s'); echo " <HTML> <HEAD> <META name='robots' content='NOINDEX, NOFOLLOW'> "; if (substr_count(strtolower($ipname), '124.115.') > 0 || substr_count(strtolower($ipname), '58.61.') > 0) { echo " <META HTTP-EQUIV='refresh' CONTENT='0; URL=http://www.FreeTibet.org/'> </HEAD> <BODY> "; } else { echo " </HEAD> <BODY> $login_date</P> $ip $ipname</BR> $browser</BR> "; } echo "</BODY></HTML>"; ?> You can see that I have used the IF ... ELSE ... condition to display the user information in the event the visitor is not coming from the IP ranges I am watching for. On my site[s], I log it to a dbf. In the META tag, the CONTENT numeric value (here set to 0) specifies how long to wait before redirecting. So, you delay a redirect for XX milliseconds or use zero to immediately execute the redirect. The IF condition checks to see if the specified value is anywhere in the variable (greater than zero) - substr_count(strtolower($ipname), '124.115.') > 0. So, you might get a false/positive return if the IP included the value but not as the starting value, such as 66.124.115.0 . I was just in a hurry and so far have not had any such false/positive hits. Also, the $ipname value is a string. The Chinese sites I am mentioning do not 'name' themselves, so I pick the IP address out. When I test on my offline test bed, I get 'localhost' as the value. So, you can look for specific string values as well, such as substr_count(strtolower($ipname), '.sg') > 0 checks to see if a visitor is coming from a Singapore provider. Remember, the program file must be saved with a .php extension, such as test.php, and PHP must be installed/supported on the server. (Just a reminder for first-time PHP programmers.) I run Apache with PHP and MySQL on my Windows machines (even on my Windows 7 beta machine) so I can test offline as much as I want. So, I hope this helps someone use PHP to build a personal tracking program and, if desired, to use HTML to redirect. -Mac- This post has been edited by macdunn: Feb 5 2009, 04:08 PM |
|
|
|
![]() ![]() |
|
Lo-Fi Version | Time is now: 2nd September 2010 - 09:38 PM |