09-30-02, 13:21 #1Registered User
- Join Date
- Sep 2002
- Windsor, Berks, UK
Unanswered: URL Redirection with MySQL field lookup
I'm new to this PHP thing but am loving it already!
I am a bit stuck though! Any nice knowledgeable peeps be kind enough to help me?
I am hoping to allow visitors to use short URLs based on their username and user_id looked up from my MySQL database (users table). At the moment the long URL name is a bit ugly ... e.g. http://mydomain/profile.php?mode=viewprofile&u=1 (1 being the user_id number)
What I would like is to be able to use a short URL ... something like http://mydomain/suzy (suzy being the username) which would redirect to the long URL above.
I found an ASP script that does something similar but couldn't get that to work ...
<% strTarget = Request.ServerVariables("QUERY_STRING") ' *** Possible alias reference if instr(strTarget, "~") then ' *** Remove the ~ and any .ASP from the alias strAlias = trim(right(strTarget, len(strTarget) - instr(strTarget, "~"))) strAlias = LCase(replace(UCase(strAlias), ".ASP", "")) if trim(strAlias) <> "" then ' *** Query the users table to see if this alias belongs to anyone Set recTemp = Server.CreateObject("ADODB.RecordSet") recTemp.Source = "select usename, user_id from users where alias_file = '" & Replace(strAlias, "'", "''") & "'") recTemp.ActiveConnection = conDB recTemp.Open ' *** Found user record, redirect to their list if not (recTemp.BOF and recTemp.EOF) then strRedir = "dvd_list.asp?user_id=" & Server.URLEncode(trim(recTemp("User_ID"))) recTemp.Close Set recTemp = Nothing Response.Redirect strRedir end if recTemp.Close Set recTemp = Nothing end if end if ' *** No alias link was found. Write 404 status to the client and display error message Response.Status = "404 Not Found" %> <html> <head><title>404 Not Found</title></head> <body> 404 Not Found </body> </html>
Thanks for your help in advance!