PHP header("Location: redirect"); function
Posted: Thu Jul 22, 2004 12:00 pm
feyd | Please use
feyd | Please use
Code: Select all
tags when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
I am trying to use this function to redirect a user to another page when they visit the site. What is happening is the user is sending a URL with a query string attached to it. I am trying to call a function from within the header function to parse the querystring and redirect the user to a new url that I create from the existing url. I have attached the code below and I so not understand why it does not work. the $redirect variable at the end has the value of the url that I want but it never gets passed back to the header function. Any help would be great.
Thank YouCode: Select all
<?php
//call getTrack funtion to break up the URL query string
header("Location: getTrack($_SERVER["QUERY_STRING"])");
function getTrack($trackfind){
/*break up the url by '&' this should have
aritst=artist1, album=album1, track=track1 in the array */
$variables=explode("&",$trackfind);
//loop through to break up the array into separate
//parts by "="
for ($i=0;$i<count($variables);$i++){
$tab=explode("=",$variables[$i]);
foreach ($tab as $x){
}
//$tab should just equal 0,track 1,track1 in array $tab
}
$track=$tab[1];
//concatenate the strings to make a new URL to redirect
$redirect="http://music.lulu.com/content/";
$redirect=$redirect . $track;
return($redirect);
}
?>feyd | Please use
Code: Select all
tags when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]