Page 1 of 1

Translate code from PHP to ASP

Posted: Wed Mar 31, 2010 9:23 am
by roice
Hello,
I found a code which I need that written in PHP while I need it in ASP
Does anyone here can help me to translate it into ASP code?

Code: Select all

<?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

?>

Code: Select all

<b><?PHP if ( !check_country() ) echo "my test"; ?></b>

Code: Select all

<?PHP
$ranges=Array(
"1040187392" => array("1040252927","IL"),
"1048584192" => array("1048592383","IL"),
);
?>

Re: Translate code from PHP to ASP

Posted: Wed Mar 31, 2010 9:43 am
by Weiry
W3Schools can help out with that.
W3Schools

Re: Translate code from PHP to ASP

Posted: Thu Apr 01, 2010 2:36 am
by roice
Thanks!

I found something that look similar, but not the same. someone can that a look please:

Code: Select all

<%
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)
%>
?