Hello, Does anyone can help me to translate the following code from PHP to ASP? <?PHP // Check user ip by country $IPaddress = $_SERVER['REMOTE_ADDR']; function iptocountry($ip) { $numbers = preg_split( "/\./", $ip); include("ip_database.php"); $code=($numbers[0] * 16777216) + ($numbers[1] * 65536) + ($numbers[2] * 256) + ($numbers[3]); foreach($ranges as $key => $value){ if($key<=$code){ if($ranges[$key][0]>=$code){$two_letter_country_code=$ranges[$key][1];break;} } } if ($two_letter_country_code==""){$two_letter_country_code="unk own";} return $two_letter_country_code; } function check_country() { global $IPaddress; $two_letter_country_code = iptocountry($IPaddress); if ( ($two_letter_country_code=="IL") OR ($two_letter_country_code=="IN") OR ($two_letter_country_code=="TR") OR ($two_letter_country_code=="VN") ) return true; else return false; } // END - Check user ip by country ?> PHP: <b><?PHP if ( !check_country() ) echo "my test"; ?></b> PHP: <?PHP $ranges=Array( "1040187392" => array("1040252927","IL"), "1048584192" => array("1048592383","IL"), ); ?> PHP:
I found something that look similar, but not the same. someone can that a look please: <% UserIp = Request.ServerVariables("REMOTE_ADDR") Response.Write(UserIp) Function Country(IPNr) arrIp = Split(IPNr, ".") <!--#include file="ip_database.asp"--> IPnumber = (arrIp(0) * 16777216) + (arrIp(1) * 65536) + (arrIp(2) * 256) + arrIp(3) Set rsCountry = cmd.ActiveConnection.Execute("Select * From [Ip-to-country] Where " & IPnumber & " >= From And " & IPnumber & " <= To;") If Not(rsCountry.EOF) Then Country = rsCountry("Country")'If number is in the database Else Country = IPnumber 'If number is not in the database then just write the IP number. End If Set rsCountry = Nothing End Function Response.Write Country(UserIp) %> PHP: ?