Page 1 of 1
can I use php to generate a redirection url?
Posted: Sat Jul 31, 2004 9:24 am
by eatrom
I have a client who has a range of agent (this can vary, agents are maintained in a mysql db) and she wants to be able to use a link with the agents name, ie: domain.com/agentname and have this redirect to the agents profile page.
Is it possible with php to do something like this? I don't see creating a redirction page for each agent; there could be a hundred. Do I need to do something at the server level to deal with pages that don't exist?
Thanks in advance
MacTrom
Posted: Sat Jul 31, 2004 9:28 am
by qads
Posted: Sat Jul 31, 2004 10:03 am
by eatrom
yeah -- I already figured the quick and dirty would be to write a custom 404 to deal with it. I'm in the midst of that now, so "We'll See"
MacTrom
Posted: Sat Jul 31, 2004 11:00 am
by eatrom
Not quite what I need.
I can't replace the server's generated 404 error page, but I was able to edit it to redirect to my own php script in order to query the database. unfortunately, I lose the actual url that was entered and found to be non-existant.
IE:
user enters
http://domain.com/agentname
404 error page redirects to not_found.php which tries to query the db for the agent name, but by now, it's lost.
I'm thinking I can use javascript in the original 404 error page to extract the url params and pass that along. I'm a bit rusty though on javascript and what I need to get this info. document.referrer doesn't work, as the url is being entered directly, not from a link.
Help???
MacTrom
Posted: Sat Jul 31, 2004 12:00 pm
by eatrom
Just thought I would post this as the code that worked for me.
I edited the 404 error doc to be:
Code: Select all
<head>
<SCRIPT LANGUAGE="JavaScript">
loc = document.location.href;
pos= loc.indexOf(".")+5 // strips the domain.com/ from the url
parm=loc.substr(pos,99)
document.write("<meta http-equiv='refresh' content='0;url=not_found.php?link="+parm+"'>");
</SCRIPT>
</head>
and then my not_found.php code page:
Code: Select all
<?
$req_url=$_REQUESTї'link'];
$sql="select AgentID from agents where concat(left(FName,1),LName) = '$req_url' ";
$rs=mysql_query($sql);
while($row=mysql_fetch_object($rs)){
$agent_id=$row->AgentID;
}
if($agent_id) {
header("Location: agent_profile.php?ag=$ag&agent_id=$agent_id");
}
... rest of page showing navigation and "File Not Found" text.
Thanks again for the help
MacTrom