If event goto url


I’ve been trying to make a script which will take a voucher code in the url and then redirect depending whether it is there or not to either a free sign up or paid subscription page. So, for example someone visiting:


goes to the normal pay-up page. Someone using:


is redirected to the free signup. But it’s not working. Could someone tell me why not (I’m no php programmer)?

Here is my code:

[php]<?php if (isset($_GET['voucher']) && $_GET['voucher'] == 'free') { ?>

<?php echo ""; ?> <?php } else { // Show the payment form page. } ?>


Many thanks.


Try it this way:

<?PHP if (isset($_GET['voucher']) && $_GET['voucher'] == 'free') { header("Location: freepagesignup.php"); } else { // Show the payment form page. } ?>

***NOTE: the location is from the root of your site. So if you start at http://mydomain/subscribe,
and in the LOCATION: there is freepagesignup.php, that file would be inside the same SUBSCRIBE folder. If you need to go to a different folder, you can use location: …/newfolder/freepagesignup.php …
Or, you can still use the full path like location: http://mydomain/newfolder/freepagesignup.php , but,
that is more typing, lol…
Hope that helps… Good luck…


Thx but it doesn’t work for me and I’ve tried pretty much every permutation. I think for some reason my website is not storing the data correctly and including it as part of the url. I’m running wordpress with a php plugin. Can you suggest how I can troubleshoot this or if you are aware of problems of running forms in WP? Many thanks/


Well, to debug it, usually, it is easiest just to display the data. So, “echo $_GET[‘voucher’];” will display what you are actually receiving from the posted page. That way you know what you are testing against. Also, for testing, you may want to change the previous post to something like this:

<?PHP if (isset($_GET['voucher'])) { echo "Voucher is set!"; if ($_GET['voucher'] == 'free') { echo "And, voucher is 'free'. Must redirect!"; // header("Location: freepagesignup.php"); } } else { echo "now show the payment form..."; // Show the payment form page. } ?>

This will display some notes for you to follow where the if’s are going… Hope that helps…


THks for your help. Still not working. But, Just as an added debug note if I add the actual voucher into my form page so it reads -


Then my paid page still does not redirect but I get the following messages:

Voucher is set!And, voucher is ‘free’. Must redirect!free

Only it doesn’t redirect?!


So, the debug code I sent you had the actual redirect commented out with “//”.
This was so you could see which flow your tests had. So, it appears it is working as it should.
Now, just have to figure out why your redirect is not working correctly.

Most likely is it the LOCATION : that is set. The page with the code that we posted is in the same folder on the site as the redirected page? If not, you have to change the LOCATION to point at the path and file. Also, the name of the location is capital-sensitive. So, freepagesignup.php is not the same as Freepagesignup.PHP…

So, remove the // before the LOCATION line to remove the commented out… And, if it does not work, tell me the folder names of where each of these files are located. To back up one level of folders on a site you use “…/” to back up two levels use “…/…/”… So, if the current page is in the root of the site and the free page is in the same root, then it should work. If the free page is inside a folder inside the root, let’s say called freepages, then the location would be LOCATION : freepages/freepagesignup.php …
If the current page is inside a folder, let say notfree and the free page is inside a folder call freepages, then, first you back up to the root and then point to the correct folder. Something like:
LOCATION : …/freepages/freepagesignup.php … This backs up one folder and goes into folder freepages and then to the file…
So, without knowing your site’s folder layout, that is all I can cover about it. Hope it helps…