How does one make a POST submit in Php?

Hi,

I know that in Php to load another page one uses:

header(“Location: $url”);

and the above call makes a GET method of submission.

What I would like to know is that how does one make a POST type of submission via Php? So for example after user clicks on the Submit button and creates a POST event, then I need to collect a bunch of information, make a bunch of calculations and make a bunch of MySQL updates and then call another page via POST, and the method must be POST, to do its job.

Regards,

This will help you to do the task on post method in php…

http://www.w3schools.com/php/php_post.asp

The OP isn’t asking how to access the variables sent by POST, but how to redirect to another page sending the variables through POST, and not in the query string (GET).

Maybe you could do it with curl? Take a look at the 4th user note.

On the few occasions I’ve needed to do it, curl has always done the job for me.

1st, yes I am not “asking how to access the variables sent by POST” but I am asking “how to redirect to another page sending the variables through POST”.

So I read the info in the URL that you have provided, of course I mean:
http://php.net/manual/en/function.curl-exec.php

But I do not see how I can pass the name & value pair to a URL via this curl_exec() call! So lets say I have:
name = $x
amount = $y
account = $z

How do I pass these name & value pairs via method POST to URL = www.myurl.com/process.php ?

ThanX

Did you see user note #4 (where a user has posted two functions, one is called curl_post) ?
That function uses http_build_query to create the query string.

(If I’m reading this correctly…) You cannot do what you describe there, it’s not a PHP issue it’s just how the web works. I would question why you feel the need to forward on the POST request at all, millions of websites get along just fine without being able to do so. (:

@Salathe: It could be a remote email login (EG to login to yahoo and check for email), it could be a proxy, or it could be for communicating with other systems that provide data.

It’s not down to us to question why the user wants to do it but it is down to us to help where we can. Oh and YES you CAN use php to make POST submissions - I’ve got a script which does it myself.

Actually Salathe, it is quite possible. I have a script which one of my servers logs into another (by POSTing the data for the login form).

@WorldNews You use the CURLOPT_POSTFIELDS option (check the curl_setopt function) to set the values you send in. You haven’t replied back to this, which probably means you read the note mentioned by guido which shows this stuff.