asp 擷取url函數小結

來源:互聯網
上載者:User

方法一:簡單,得不到參數,只有一個虛擬路徑 複製代碼 代碼如下:GetUrl =request("url")

例如:http://127.0.0.1/shiyan.asp?dfsdfsf=dsfsdfd&aa=dddd
擷取為:shiyan.asp 複製代碼 代碼如下:<%
dim changdu,url,ends,wurl
changdu=len(request.ServerVariables("URL"))
url=instrrev(request.ServerVariables("URL"),"/")
url=url+1
ends=changdu+1-url
wurl=mid(request.ServerVariables("URL"),url,ends)
%>

方法二:得到整個URL,得到參數 複製代碼 代碼如下:'得到當前頁面的地址
Function GetUrl()
On Error Resume Next
Dim strTemp
If LCase(Request.ServerVariables("HTTPS")) = "off" Then
strTemp = "http://"
Else
strTemp = "https://"
End If
strTemp = strTemp & Request.ServerVariables("SERVER_NAME")
If Request.ServerVariables("SERVER_PORT") <> 80 Then strTemp = strTemp & ":" & Request.ServerVariables("SERVER_PORT")
strTemp = strTemp & Request.ServerVariables("URL")
If Trim(Request.QueryString) <> "" Then strTemp = strTemp & "?" & Trim(Request.QueryString)
GetUrl = strTemp
End Function

例如:http://127.0.0.1/shiyan.asp?dfsdfsf=dsfsdfd&aa=dddd
擷取為:http://127.0.0.1/shiyan.asp?dfsdfsf=dsfsdfd&aa=dddd

方法三:得到虛擬路徑,得到參數 複製代碼 代碼如下:Private Function GetUrl()
Dim ScriptAddress,M_ItemUrl,M_item
ScriptAddress = CStr(Request.ServerVariables("SCRIPT_NAME")) '取得當前地址
M_ItemUrl = ""
If (Request.QueryString <> "") Then
ScriptAddress = ScriptAddress & "?"
For Each M_item In Request.QueryString
If M_item = "page_num" Then Exit for '此處的作用就是過濾掉Page_num這個頁次的參數(該參數是在page_turn.asp中自行設定的,根據個人設定而變),否則每次翻頁都會疊加這個參數,雖然不影響功能,但總歸不太好吧~~
If InStr(page,M_Item)=0 Then
M_ItemUrl = M_ItemUrl & M_Item &"="& Server.URLEncode(Request.QueryString(""&M_Item&""))
else
M_ItemUrl = M_ItemUrl & M_Item &"="& Server.URLEncode(Request.QueryString(""&M_Item&"")) & "&"
End If
Next
Else
ScriptAddress = ScriptAddress & "?"
end if
GetUrl = ScriptAddress & M_ItemUrl
End Function

例如:http://127.0.0.1/shiyan.asp?dfsdfsf=dsfsdfd&aa=dddd
擷取為:/shiyan.asp?dfsdfsf=dsfsdfd&aa=dddd

方法四:只擷取參數部分字串 複製代碼 代碼如下:Function GetUrl()
On Error Resume Next
Dim strTemp
If LCase(Request.ServerVariables("HTTPS")) = "off" Then
strTemp = "http://"
Else
strTemp = "https://"
End If
strTemp = strTemp & Request.ServerVariables("SERVER_NAME")
If Request.ServerVariables("SERVER_PORT") <> 80 Then strTemp = strTemp & ":" & Request.ServerVariables("SERVER_PORT")
strTemp = strTemp & Request.ServerVariables("URL")
If Trim(Request.QueryString) <> "" Then strTemp = strTemp & "?" & Trim(Request.QueryString)
GetUrl = strTemp
geturl=mid(geturl,instr(geturl,"?")+1)
End Function

例如:http://127.0.0.1/shiyan.asp?dfsdfsf=dsfsdfd&aa=dddd
擷取為:dfsdfsf=dsfsdfd&aa=dddd

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.