Reputation: 103
I'm trying to setup a PHP redirect based off a variable in the URL. Here's my current code:
$afflink = $_GET['trial'];
header( 'Location: http://website.com/members/aff.php?aff=$afflink' ) ;
However, right now it's literally redirecting to http://website.com/members/aff.php?aff=$afflink
instead of getting the trial
parameter from the URL and using it in the redirect code.
What exactly am I doing wrong here?
Upvotes: 0
Views: 258
Reputation: 9285
Sigle quotes are interpreted literally, so change to:
$afflink = $_GET['trial'];
header("Location: http://website.com/members/aff.php?aff=$afflink");
Or:
$afflink = $_GET['trial'];
header('Location: http://website.com/members/aff.php?aff=' . $afflink);
But for a minimum security, i suggest you to use:
$afflink = filter_input(INPUT_GET, 'trial');
header('Location: http://website.com/members/aff.php?aff=' . $afflink);
Upvotes: 1
Reputation: 28795
If a string is in single quotes '
, a variable within will not be evaluated. Use doubles "
:
header( "Location: http://website.com/members/aff.php?aff=$afflink" ) ;
Upvotes: 1