Is there a way in asp to retrieve part of the URL and use it say the url was http://localhost/site/craig is there anyway of retrieving the word craig so to use it in the page This is because i could have other addresses that are for example http://localhost/site/Jon where i need to retrieve the word jon
Here is some code to do it. Lets say the current page is simply "http://www.mysite.com/view_user.asp" This is all you need to get you the current page URL <% Thispage = Request.ServerVariables("script_name") %> Now, if your page has Querystring info and variables you want as well. Like so "http://www.mysite.com/view_user.asp?ID=1&Name=Fred" you would use code like this. <% Thispage = Request.ServerVariables("script_name") & "?" & Request.Querystring %>
so i that returned /files/craig/Default.asp how could i just put the name craig into a string baring in mind the /files/ is always going to be there and the file will always be called default.asp ie i could have directories /files/jon/Default.asp where i need jon to be returned...
here is a sample where I keep the domain name only from the refering site maybe you can figure out I don't want to post the script for you, I want to help you achieve it
<% Function ParseDomainFromURL(url) urlParts = split(url,"/") ParseDomainFromURL = urlParts(2) End Function domain = parseDomainFromURL("http://www.mobile.am/?lang=en") %> I wanna work it out as well... i guess i need to pass something to the function url what i dont understand is why i need this.. domain= surely that should be calling the function.. and where is the output?
<% Function ParseDomainFromURL(url) urlParts = split(url,"/") ParseDomainFromURL = urlParts(2) End Function url = parseDomainFromURL(Request.ServerVariables("URL")) Response.Write(url) %> would be my guess
or could do <% sMyString = Request.ServerVariables("URL") sMyString = Replace(sMyString, "/", "") sMyString = Replace(sMyString, "files", "") sMyString = Replace(sMyString, "default.asp", "") sMyString = Replace(sMyString, "Default.asp", "") Response.Write sMyString %> Which one is better?