We help IT Professionals succeed at work.

Make PHP submit POST variables

dban00b asked
Last Modified: 2011-10-03
If I want PHP to submit GET variables it's easy.
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 :)
Watch Question

Guy Hengel [angelIII / a3]Billing Engineer
Most Valuable Expert 2014
Top Expert 2009

you might consider using session data instead:

header("Location: http://www.example.com/activateuser.php);

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

$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.


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.

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"

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.


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:

$var_array = put variable into array or class?

redirect ("login.php","POST",$var_array);
Unlock this solution and get a sample of our free trial.
(No credit card required)


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.


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>");


I also tried manually assigning the post variables:

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.



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']?>">

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

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.