我现在有一段ASP写的IP查询代码:
<%
IP=request("ip")
if IP="" then
IP = Request.ServerVariables("REMOTE_ADDR") 
end if
Function cacuIp(ip)
On Error Resume Next
Dim srIp, aIp
srIp=0
aIp = Split(ip,".")
If UBound(aIP)<>3 Then
cacuIP=0
Exit Function
End If
For i=0 To 3
srIp=srIp+(CInt(aIP(i))*(256^(3-i)))
Next
cacuIp=srIp-1
If Err Then cacuIp=0
End Function 
Set CONN=Server.CreateObject("ADODB.Connection")
CONN.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ="&Server.Mappath("ip.mdb")iIp=cacuIp(IP)
SQL = "SELECT country,city FROM 25175IP WHERE ip1<=" & iIp & " AND ip2>=" & iIp
Set rs = CONN.Execute ( SQL )
If rs.Eof Then
sPlace="查无记录"
Else
sPlace=rs(0)&" "&rs(1)
End If
Set rs=Nothing
Response.Write "<a href=""http://www.25175.com""> 你查询的IP所在地为:"&sPlace&" ("&ip&")</a>"
%>

解决方案 »

  1.   

    这是我转写的PHP代码:
    <?php
    function cacuIp($sIP)
    {
    $srIp=0;
    $aIp = split(".",$sIP);
    For($i=0;$i<4;$i++){
    $srIp=$srIp+(intval($aIP($i))*(256^(3-$i)));
    cacuIp=$strIp-1;
    }
    }//End Function 
    ?>哪里写错了吗?
      

  2.   

    关于查询mdb数据库的暂时没有写上函数哪里写错了?
      

  3.   

    ^是位运算符吧.你觉得是什么?
    UBound对应的php函数是什么??