PHP - Redirect not working correctly

Hi Guys,

I need your help please. I’m trying to load a URL like the following:

http://www.xxxxx.com/track/clickbeta.php?p=3&affid=21&subid=testurl&lp=1

Now as you can see in the url i have the following:

&lp=1

Here is my code:



//XXX LP - XXX UK
if ( $lp == "1" ) {
	$url="xxxxxxxxxxxxxxx.com";
};

//XXX LP - XXX UK
if ( $lp == "2" ) {
	$url="xxxxxxxxxxxxxxxxxx.com";
};

if (isset($lp)) {
    //do nothing
} else {

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Oops theres an error, our highly trained monkeys have been notified.");

$query = sprintf("SELECT URL FROM programs WHERE ID ='%s'",
			quote_smart($p));

mysql_query($query) or dies(mysql_error());
$result = mysql_query($query);
$url=mysql_fetch_array($result, MYSQL_ASSOC);
mysql_close();


};

$string =$url['URL'];
$string = addslashes($string);
$urlgo=eval("\\$string = \\"$string\\";");
header( 'Location: '.$string.'' ) ;

There is more code than the above such as connecting the the database and variable setting but i the i think with the above you can see what im trying to do. But how ever when i try the URL above with the &lp=1 it just takes me to:

http://www.xxxxxxxxxxx.com/track/h

and not the URL thats in the script. Can someone help me please and tell me where im going wrong?

Thank you.

I’m not sure why you have addslashes and eval there. What happens if you just do:


$string = $url['URL']; 
header( 'Location: '.$string ); 
exit();

Hi,

I was told to do that as sometimes the URL will have a variable in it for example http://www.google.com/?id=$affid

But when loading the URL $affid wasnt being replaced with the data thats stored in that variable and was just sending people to the URL with the variable as PHP code. So i was told to do that and then it started to work.

Any help with this guys would be much appreciated.

Thank you!