Link to home
Create AccountLog in
Avatar of dban00b
dban00b

asked on

Make PHP submit POST variables

If I want PHP to submit GET variables it's easy.
<?php
$User_ID=1;
header("Location: http://www.example.com/activateuser.php?UserID=".$User_ID);
?>

but I need to use POST variables.
I have googled, tried, and been unsuccesful with a whole slew of options, so hopefully, someout there can help me!

Thanks :)
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

you might consider using session data instead:

<?php
session_start();
$SESSION["User_ID"]=1;
header("Location: http://www.example.com/activateuser.php);
?>

 and in the page activateuser.php, you do like this:

<?php
session_start();
$User_ID = @$SESSION["User_ID"];

 echo "USER ID = $User_ID activated.";
?>
there are no such specific GET or POST variables.
GET param variables are one which are sent in URL, whereas POST params are hidden tag or normal tags which are submitted to a page and/or itself using method="POST" in the form of your html page.
Avatar of dban00b
dban00b

ASKER

@angelll
the destination file is not mine, so I cannot add session data to it, it is also why I must use POST rather than GET.

@asvforce
true, the variables in question are really "data sets" and GET or POST are the methods of tranmission
so when I say "GET Variables" I really meant "form data sets sent using the HTTP GET method defined at http://www.w3.org/TR/html4/interact/forms.html#h-17.13.1"

@both
esentially, my target file will only accept form data sets using the HTTP POST method, not URI encoded
If I make my own simple HTML form and submit it, it works fine, but I want this extra step hidden from the user

thanks for your help
Could you be more specific about what you're trying to do? Setting the header to include query parameters does not technically make PHP submit GET variables. All it's doing is making the variables defined by the query parameters available through the $_GET array -- because they're query parameters and that's what the $_GET array does.

If you want variables to be available via the $_POST array, then you need to A) have form variables submitted using the POST method or B) set the variables with PHP. The second option does not make any sense, because it doesn't allow userinteraction... but neither does your model, at least not exactly as written.

The solution to your problem really depends on what you're trying to accomplish.
Avatar of dban00b

ASKER

That might be the crux of the problem right there!! I don't really know what I need PHP to do, I just know what I want the results to be.  Here is my scenario spelled out more verbosely so that it might help:

START: Login form in a Flash file that can only send the login variables via the HTTP GET method by encoding them onto a URI/URL

FINISH: phpbb's login.php that can only receive the login variables via the HTTP POST method

To get from start to finish I need something in the middle that can take the variables via the HTTP GET method and push them back out via the HTTP POST method.

Psudeo Code Guess:
<?php
$username=$_GET['username']
$md5pass=$_GET['password']

$var_array = put variable into array or class?

redirect ("login.php","POST",$var_array);
?>
ASKER CERTIFIED SOLUTION
Avatar of JimQode
JimQode

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of dban00b

ASKER

Unfortunately that won't work, because I can't send the variables from the source using the HTTP POST method, I can only send them using the HTTP GET method.
Avatar of dban00b

ASKER

OH, i see what you were trying there, but...it didn't work, the form does auto-submit itself, it does redirect after doing so, by the destination file gives me:

Notice: Undefined index: username in D:\www\codetesting\testrecievePOST.php on line 18
where line 18 is echo ("<P>Your username is ".$_POST['username']."<P>");

Avatar of dban00b

ASKER

I also tried manually assigning the post variables:
$_POST['username']=$_GET['username'];

Of course it didn't work, but it was worth a shot.  I could reference my manually assigned $_POST['username'] later in the same page with success, but the header()location redirect couldn't see it.

Avatar of dban00b

ASKER

VIOLA!!!!!!!!!!!!!!!!

Got it!! JimQode:--you we're soooo close I don't know why I missed it until now.  There's no reason to do a self-submit redirect, when you can auto submit straight to the target

<body onLoad="document.forms[0].submit();">
<form method="POST" action="http://www.example.com/activateuser.php">
<input type="hidden" name="username" value="<?=$_GET['username']?>">
<input type="hidden" name="password" value="<?=$_GET['password']?>">
</form>
</body>

AND DONE!!!
It works, I'm in, I'm golden, Thanks for everyone's help!!