[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 7809
  • Last Modified:

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 :)
0
dban00b
Asked:
dban00b
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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.";
?>
0
 
Ashish PatelCommented:
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.
0
 
dban00bAuthor Commented:
@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
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
nsBlackOpsCommented:
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.
0
 
dban00bAuthor Commented:
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);
?>
0
 
JimQodeCommented:
You can post the form to the script itself then redirect it. When you do a header redirect any post variables you have will also be redirected.

this should do:


<?php

if (isset($_POST['username'])) header("Location: http://www.example.com/activateuser.php);

?>
<body onLoad="document.forms[0].submit();">
<form method="POST">
<input type="hidden" name="username" value="<?=$_GET['username']?>">
<input type="hidden" name="password" value="<?=$_GET['password']?>">
</form>
</body>
0
 
dban00bAuthor Commented:
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.
0
 
dban00bAuthor Commented:
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>");

0
 
dban00bAuthor Commented:
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.

0
 
dban00bAuthor Commented:
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!!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now