Dustin
Dustin

Reputation: 89

Code Help - PHP, Query String, Redirect

I'm trying to pass variables to a simple PHP script and have it redirect to different URLs depending on the values in the query string.

Here's what I have in bonus.php:

<?php

if ($_GET['pid'] == '3') {
    $bonus = "copy-paste-traffic";
}
elseif ($_GET['pid'] == '5') {
    $bonus = "lazy-affiliate-riches";
}

$redirect = "http://affiliatesilverbullet.com/.'$bonus'.-bonus/?mid=.'$_GET['mid']'.&pid=.'$_GET['pid']'.";

echo $redirect;

page_redirect($redirect);

?>

I want queries to redirect as follows:

asbfree.com/bonus.php?mid=dstruckman&pid=3 -> affiliatesilverbullet.com/copy-paste-traffic-bonus/?mid=dstruckman&pid=3

asbfree.com/bonus.php?mid=dstruckman&pid=5 -> affiliatesilverbullet.com/lazy-affiliate-riches-bonus/?mid=dstruckman&pid=3

But it's not working.

What am I doing wrong?

Please show me how to fix my bonus.php script to make this work.

Thanks in advance!

Dustin

Upvotes: 0

Views: 1056

Answers (3)

ATLChris
ATLChris

Reputation: 3296

I would use header("Location: $redirect"); instead of page_redirect($redirect);.

Upvotes: 0

JiminP
JiminP

Reputation: 2142

I think you may change

$redirect = "http://affiliatesilverbullet.com/.'$bonus'.-bonus/?mid=.'$_GET['mid']'.&pid=.'$_GET['pid']'.";

to

$redirect = "http://affiliatesilverbullet.com/".$bonus."-bonus/?mid=".$_GET['mid']."&pid=".$_GET['pid'];

EDIT : ...change elseif to else if, page_redirect to http_redirect, and remove echo or place after redirect function.

Upvotes: 1

Paul Nicholson
Paul Nicholson

Reputation: 557

One of the issues may be your variable interpolation. Replace

$redirect = "http://affiliatesilverbullet.com/.'$bonus'.-bonus/?mid=.'$_GET['mid']'.&pid=.'$_GET['pid']'.";

with

$redirect = "http://affiliatesilverbullet.com/{$bonus}-bonus/?mid={$_GET['mid']}&pid={$_GET['pid']}";

Next time you post a question it would be helpful to post the error message you are receiving.

Upvotes: 0

Related Questions