Forum Moderators: coopster

Message Too Old, No Replies

Passing Along A Variable

How do I pass along a variable in a redirect?

         

Croatbag

12:13 am on Dec 1, 2006 (gmt 0)

10+ Year Member



Hi All,

I had a question I think is fairly simple for someone familiar with PHP, but unfortunately I am not one of those.

I have a webpage and I put a link on that website through a php redirect. For example www.xyz.com/12.php?ID=12345

This then goes to a page that has a quick redirect to a website.

www.website2.com/ID=#*$!XX

What I want to do is have the ID from the first link be passed into this link during the redirect. I looked online and was only able to find this. I can copy it and make it echo but I can't get it into the link.

PHP - Basic passing variables via url
Pass variables to a page using the question mark, for example mypage.php?value=hello.

Access these variables with the _GET command. code snippet:

<?php
// for example: thispage.php?word=abracadabra

$val = $_GET['word'];
echo "the word is: $val";

?>

What I did is this, but it does not work I get $val as the ID instead of the original ID.

<?php
header( 'Location: [xyz.com...] ) ;
$val = $_GET['k'];
?>

Do I need to do something on the 1st page to make it try to pass along the variable in the first place? Right now all I have is the link saying www.xyz.com/?ID=12345 and nothing else so maybe its not set up in the 1st place to pass it.

Much thanks in advance to whoever can answer this for me and save me a ton of time.

sned

12:21 am on Dec 1, 2006 (gmt 0)

10+ Year Member



You just need to switch the statements around, and put the header in double quotes (")

<?php
$val = $_GET['k'];
header( "Location: [xyz.com...] ) ;
?>

-sned

Croatbag

12:30 am on Dec 1, 2006 (gmt 0)

10+ Year Member



That did the trick thanks alot Sned