Sometimes, you may want to get the current page's URL in a browser window to display the URL. For example, if you want your visitors to submit a blog post to Digg you need to get the exact same URL. There are many other reasons too. Here's how you can do that.
The following code is added to the page:
<%
function Curpageurl ()
Dim s, Protocol, port
If Request.ServerVariables ("HTTPS") = "on" Then
s = "S"
Else
s = ""
End If
protocol = Strleft (LCase (Request.ServerVariables ("Server_protocol")), "/") & S
If Request.ServerVariables ("server_port") = "Then"
Port = ""
Else
Port = ":" & Request.ServerVariables ("Server_port")
End If
Curpageurl = protocol & "://" & Request.ServerVariables ("SERVER_NAME") &_
Port & Request.ServerVariables ("Script_name")
End Function
function Strleft (STR1,STR2)
Strleft = Left (Str1,instr (STR1,STR2)-1)
End Function
%>
Now you can get the URL of the current page to use the line
<%
Response.Write (Curpageurl ())
%>
If your page has a string of information you want to query and you can try this code:
<%
Response.Write (Curpageurl () & "?" & Request.ServerVariables ("Query_string")
%>
The following example shows how to do this:
<%
function Curpagename ()
Dim pagename
PAGENAME = request.servervariables ("Script_name")
If inStr (pagename, "/") > 0 Then
pagename = right (pagename, Len (pagename)-instrrev (PAGENAME, "/")
End If
Curpagename = pagename
End Function
Response.Write ("The current page name is" & Curpagename ())
%>