Forum Moderators: coopster

Message Too Old, No Replies

php grab url (change) and redirect

         

sahand1010

10:30 pm on Sep 19, 2008 (gmt 0)

10+ Year Member



Hi,
I have been practicing PHP for only a few months and wanted to change some pages to php. Here is my problem, I have some old links that are using an old product id number.
ex. domain.com/showitem.php?item=R600

I want to create a php page (showitem.php) to grab the url and change the item# and redirect to a different page.
ex. domain.com/newitem.php?item=N300

I have already written the code to query the database based on the old item number and return the new id, but i am not sure how to strip the old id from the url, replace it with the new and redirect.

Thanks in advance for the help!
(being a noob, I am not sure if I described my problem clearly)

Anyango

5:36 am on Sep 20, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hey, Welcome to WebmasterWorld!

showitem.php file
<?
$oldItem=$_GET["item"]; //this gets "item" from url
/*
here goes all your mysql code to grab new item number against this $oldItem value, lets say you save the new item number in variable $newItem
then
*/
header("Location : http://example.com/newitem.php?item=$newItem");
?>

sahand1010

1:52 pm on Sep 23, 2008 (gmt 0)

10+ Year Member



Thank you Anyango,
That worked beautifully!

At first I couldn't get the header function to redirect correctly. It would display an error but, after reading the manual I found out that I couldn't have any output before the header function (I was echoing the variables).

Thank you again :)

Anyango

7:55 pm on Sep 23, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Cool.
I was thinking of saying that thing about header function when i was replying to your post but thought it might not be needed , glad you figured it out.