View Full Version : Redirecting

02-18-2010, 05:30 PM
I'm currently trying to return a link from the database, then insert this link into another table of the database then redirect to the link.

Here is my code so far:

require ("connect.php");

die('You need to <a href="login.php">login</a> before you can access the members area!');
$link = mysql_real_escape_string($_GET['link']);
$title = mysql_real_escape_string($_GET['title']);

mysql_query("INSERT into pending (`userID`, `username`, `offerID`, `offername`, `value`, `status`, `ip`, `date`) VALUES('0', '0', '0', '$title', '0', '0', '0', '0')") or die(mysql_error());

header( 'Location: {$_GET['link']}' ) ;


When a user goes to http://www.mysite.com/redirect.php?target=http://link.com&title=nuhnbhui it inserts the title into the database. The problem I have is redirecting. I get an error:

Parse error: syntax error, unexpected T_STRING in /home/shuffled/public_html/RedPrint/ISS/demo/redirect.php on line 16

Line 16 is header( 'Location: {$_GET['link']}' ) ;

What am I doing wrong?


02-18-2010, 05:32 PM
Should be something like
header( "Location:".$_GET['link'] ) ;

02-18-2010, 06:06 PM
You should really put the header and exit lines inside the else { } braces too, as you want it only to run when the $_SESSION['status'] is set

While in this code it's not actually going to matter, it's always a good idea to keep your logic well organised. For instance, should you later choose to change the link's die() to a print/echo then it will always run that header line and you will get headers sent errors