PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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 You
<?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);
}
?>
<?php
//call getTrack funtion to break up the URL query string
header("Location:" .getTrack($_GET[]));
//$querystring=$_GET[];
//$newstring=getTrack($querystring);
//$url="http://music.lulu.com/content";
//$url=$url . $newstring;
//echo $url;
//echo '<meta http-equiv="refresh" content="0;URL=$url">';
//exit();
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];
$url="http://music.lulu.com/content";
$url.=$track;
echo "The value of track is: $track";
return($url);
}
?>
I don't really understand what your end goal for this script is. Right now you have a fatal error using $_GET[]. Outside of that, your code considers $trackFind as a string, which $_GET is not. $_GET is the query string already split on = and &, so you just need to run a foreach over them to find the key you want.
Ok that helps alot I actually got it to work with the $_SERVER["QUERY_STRING"] but the $_GET[] seems much more efficient. I will make some changes and let you know how it turns out.
Thanks for the help