Forum Moderators: coopster

Message Too Old, No Replies

Help: PHP parsing variable not working

         

breham

3:58 pm on Nov 7, 2006 (gmt 0)

10+ Year Member



Hi,

I have a page which when the visitor clicks on a link it takes them to redirect.php

Up until now I have parsed a simple URL with trailing variables i.e

<a href="redirect.php?variable1=a">

Then picked these variables up using $_GET in the redirect.php page.

Now as these details are include an affiliate link I thought I'd send the variables via a <Form> tag rather than <a href> to hide the details from my visitors:

<form action="redirect.php" etc>
<input type="hidden" name="variable1" value="a">
<input type="submit">

This gets the info into redirect.php as before but when redirect.php does it's stuff it tries to redirect but instead of going to http://www.example.com (which is what variable1 equates to) it tries to open this:

/currentdirectory/http://www.example.com

and so fails

My redirect page code is simply:

<?php
// get the search string passed to the page, and the page number if there is one
$url = '';
$url = $_GET['variable1'];
header('Location: '.$url,true);
?>

This worked perfectly when using the a href method.

Someone please help!

Cheers
Brett

[edited by: coopster at 4:28 pm (utc) on Nov. 7, 2006]
[edit reason] examplified url [/edit]

barns101

6:12 pm on Nov 7, 2006 (gmt 0)

10+ Year Member



Is your form using the GET or POST method? If it's post, you need to change your redirect code as follows:


<?php
// get the search string passed to the page, and the page number if there is one
$url = '';
$url = $_POST['variable1'];
header('Location: '.$url,true);
?>

breham

9:41 am on Nov 8, 2006 (gmt 0)

10+ Year Member



Thanks Barns01

It wasn't to do with the form action but I have fixed it now.

The issue was the $url was being urlencoded in the 1st page and needed urldecoding on the redirect page.

Interesting that it only needs to do this when parsed from within a <form> rather than a <a href

Thanks again
Brett