PHPBuilder - Redirect and Block surfers by Country or Anonymous Proxy



RSS Twitter
Snippets Http

Redirect and Block surfers by Country or Anonymous Proxy

by: Adam
|
March 14, 2004

Version: 1.0

Type: Full Script

Category: HTTP

License: GNU General Public License

Description: This code allows webmasters to take control of surfers to their sites. By redirecting clients according to what country they come from or whether or not the surfer is using an anonymous proxy, webmasters are able to provide customised content directly to their audience.



To use the code you will need to change 4 variables:
1. Add the page that you want allowed users to be redirected to;
2. Add the page that you want blocked users to be redirected to;
3. Add your Country Check (www.countrycheck.com) user number;
4. Add your Country Check password;
5. Save the file as "index.php" and ftp it. Make sure to rename your original index file to avoid overwriting it. 


<?php

$ok='http://www.YOURSITE.com/ALLOWEDPAGE';
$not='http://www.YOURSITE.com/NOTALLOWEDPAGE';
$ip=$_SERVER['REMOTE_ADDR'];

$fp = @fsockopen("countrycheck.com", 80, $errno, $errstr, 10);
if(!$fp)
{}
else
{
   	$result = '';
	@fputs($fp,"GET http://www.countrycheck.com/ip.aspx?u=USERNUMBER&p=PASSWORD&t=1&ip=$ip HTTP/1.0\r\nHost: $_SERVER[HTTP_HOST]\r\n\r\n");
	@socket_set_timeout($fp, 10);
    while(!@feof($fp))
    {
      	$result .= @fgets($fp, 1024);
    }
	@fclose($fp);
}

if(strpos($result, 'NO') === false) {
header("Location: $ok");
exit;
}
else {
header("Location: $not");
exit;
}
?>

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Adam

Comment:



Comment:

(Maximum characters: 1200). You have characters left.