...

View Full Version : Redirecting



Skippy
02-18-2010, 04: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:


<?php
session_start();
require ("connect.php");
require("functions.php");

if(!isset($_SESSION['status'])){
die('You need to <a href="login.php">login</a> before you can access the members area!');
}else{
$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']}' ) ;
exit;

?>

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?

Thanks.

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

JAY6390
02-18-2010, 05: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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum