代码改变世界

ASP得到当前页面完整地址

2008-06-12 21:30  Iron  阅读(389)  评论(0编辑  收藏  举报

"http://" & Request.ServerVariables("HTTP_HOST") & Request.ServerVariables("PATH_INFO") & "?" & Request.ServerVariables("QUERY_STRING")

Request.ServerVariables("HTTP_HOST") '得到域名

Request.ServerVariables("PATH_INFO") '得到当前文件路径

"?" & Request.ServerVariables("QUERY_STRING") '得到参数

做asp程序的时候,有时候需要用的着!

dim url

url=url&"http://"&request.ServerVariables("Server_NAME")&request.ServerVariables("SCRIPT_NAME")

if(len(trim(request.ServerVariables("QUERY_STRING")))>0) then

url=url & "?" & request.ServerVariables("QUERY_STRING")

end if

response.Write url

 

获取IP的函数

Function getIP()

Dim strIPAddr

If Request.ServerVariables("HTTP_X_FORWARDED_FOR") = "" OR InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), "unknown") > 0 Then

strIPAddr = Request.ServerVariables("REMOTE_ADDR")

ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",") > 0 Then

strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",")-1)

ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";") > 0 Then

strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";")-1)

Else

strIPAddr = Request.ServerVariables("HTTP_X_FORWARDED_FOR")

End If

getIP = Trim(Mid(strIPAddr, 1, 30))

End Function