Username
Username

Reputation: 103

Get parameter from URL and redirect?

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

Answers (2)

Marcio Mazzucato
Marcio Mazzucato

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

Adam Hopkinson
Adam Hopkinson

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

Related Questions