PHP Redirect Script not working

I have uploaded this script provided to me by the marketplace I work with to redirect affiliate traffic based upon a parameter that designates which sales page (or the typical home page) the visitor gets sent to. The Script is based on a parameter that the affiliate chooses based upon the nature of the promotion they are doing.

However, this script results in one of two things. The first, it completely bypasses the script and all 3 parameters sends the traffic to the homepage. The second being an Internal HTTP 500 error. However, I do believe I fixed the 500 error code cause before shutting down the script so our traffic wouldn’t be affected during daytime hours. So my question is why would all 3 parameter IDs go to the home page? Is there something I’m forgetting to put in the script? Server runs PHP7. Below is the script (url3 is set as the home page, I had to remove the url due to forum restriction and me being a new user)…

    <?php

$url1="http://www.cleanuptheprofits.com/officecleaningkit";
$url2="http://www.cleanuptheprofits.com/housecleaningkit";
$url3="HomePageURL"; 


if ($_GET['pid'] == "1")
{
header("Location: $url1".preserve_qs());
}
elseif ($_GET['pid'] == "2")
{
header("Location: $url2".preserve_qs());
}
elseif ($_GET['pid'] == "3")
{
header("Location: $url3".preserve_qs());
}


else
{
header("Location: $url3".preserve_qs());
}


?>

You could simplify that using a dictionary, but I think your issue is in the preserve_qs(). I don’t see it there. Is there a pid passed in when they get directed to that page?

I am a rookie (only dabbled in when necessary) when it comes to PHP (primarily deal with Web Strategy), so please excuse my ignorance when it comes to this question… What exactly does the preserve_qs() do under normal circumstances?

But yes, the pid does display in the affiliate link as well as in the URL when they land on the page from the affiliate link. (I believe this answers your question)

use === in php , almost never == . … but that shouldn’t matter here since every value in $_GET is always a string

Before the IF statement add var_dump($_GET) to confirm the values are actually what you expect them to be.

That is not a standard PHP function. Someone involved in the creation of the website or some 3rd party code that the project depends on is where that function is coming from. We have no idea what it does. I assume it takes whatever was originally in $_GET and appends it to the urls used in the header() redirect.

Ok, I cant look at that code anymore. Here…

<?php
$url1="http://www.cleanuptheprofits.com/officecleaningkit";
$url2="http://www.cleanuptheprofits.com/housecleaningkit";
$url3="HomePageURL";

if (isset($_GET['pid']))  {
die(header("Location: $url{$_GET['pid']}".preserve_qs()));
}
die(header("Location: $url3".preserve_qs()));
1 Like

You have that reversed.

123 == “123foo”; // true
123 === “123foo”; // false

I’ll take the predictable sanity of === thank you.

PHP Double Equals == equality chart:

PHP Triple Equals === Equality chart:

1 Like

That code worked like a charm! Thank you! :grin:

Hopefully you learned something from what I did and not just copy/pasted it.

Sponsor our Newsletter | Privacy Policy | Terms of Service