asp 获取url函数小结
程序员文章站
2022-07-05 19:30:18
方法一:简单,得不到参数,只有一个虚拟路径 复制代码 代码如下: geturl =request("url") 例如:http://127.0.0.1/shiyan.as...
方法一:简单,得不到参数,只有一个虚拟路径
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
复制代码 代码如下:
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
上一篇: 防盗链接ASP函数
下一篇: 皮肤瘙痒怎么办 6个招数有效止痒