Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PURL 2

Status
Not open for further replies.

Swi

Programmer
Feb 4, 2002
1,963
US
I was wondering if anyone could help me with parsing a URL so I can perform a database lookup in or to create a custom landing page.

PURL (personlized URL) - Ex. - test.com/JohnSample

I would like to parse the JohnSample bit off of the URL and perform a DB query on my ASP page to return information about the user before the page is rendered so it is specific to that person.

Any help would be greatly appreciated.

Thanks.

Swi
 
Split Request.ServerVariables("PATH_INFO") on the '/' then read off the last array element.


Here's a function I use

Code:
public function GetPath()
   dim ThisPage
   ThisPage = Split(Request.ServerVariables("PATH_INFO"), "/")
   if FldrCount > ubound(ThisPage) then
   else
      GetPath = ThisPage(ubound(ThisPage))
   end if
end function

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
And

GetPath = ThisPage(ubound(ThisPage))

Should be

GetPath = ThisPage(ubound(ThisPage)-1)

If you need to remove the document name (default.asp) from the URI.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Thank you very much. I will give it a shot.

Swi
 
Would this be reliable with all browsers? Thanks.

Swi
 
Browsers have nothing to do with server side code.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Agreed. Thank you for the response. Just had a colleague metion something to me.

Swi
 
This works well however how do I rewrite the URL and display the default.asp file and do a database lookup to display the variable content on the page.

Any help is greatly appreciated.

Thanks.

Swi
 
Not sure all that you are asking, so sorry if i'm being too simplistic or general...

how do I rewrite the URL and display the default.asp file
do a response.redirect?

do a database lookup to display the variable content on the page
create connection string, do a database lookup, response.write what you want?
 
Basically there are two ways you can do this from what I understand.

1. Use a query string: website.com?name=Swiler
2. Use an custom 404 error page in IIS to rewrite the URL and pass a session variable to do the DB lookup

Not really sure which way I want to go. I guess it depends on what the client wants.

Pretty URL = website.com/Swiler
Query String (embedded in maybe a QR code) = website.com?name=Swiler

If anyone has any alternatives let me know.

Thanks.

Swi
 
Yes, that is my understanding as well. I don't know of another alternative besides those two.

The custom error page makes the URL look nicer and easier to type, remember etc., but requires a change to IIS to implement (albeit a minor one). The query string is faster to implelent, but the URL will not be as clean.
 
Yep. Thank for the confirmation and feedback.

Swi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top