Hi,
I'm just wondering how I can send POST data to a url in PHP (without a form)
I'm going to be using it to send variable to complete and submit a form.
Thanks
Hi,
I'm just wondering how I can send POST data to a url in PHP (without a form)
I'm going to be using it to send variable to complete and submit a form.
Thanks
<form method="post" action="somewhere.php">
All fields will now be send via POST
edit: of course this is not really POST, so Babiker is right, but I assume that this is what he was looking for: namely no parameters in the adress bar
<form method="GET" action="someScript.php>
<input type="text" name="someInput">
<input type="text" name="someOtherInput">
<input type="submit">
</form>
Mind you, this is not POST. You can't send via URL using POST. On submit you shall get something like this in URL:
/someScript.php?someInput=some_value&someOtherInput=some_other_value
Your question is not particularly clear, but in case you want to send POST data to a url without using a form, you can use either fsockopen or curl.
If you're looking to post data from to a url from PHP code itself (without using an html form) it can be done with curl. It will look like this:
$url = 'http://www.someurl.com';
$myvars = 'myvar1=' . $myvar1 . '&myvar2=' . $myvar2;
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $myvars);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec( $ch );
This will send the post variables to the specified url, and what the page returns will be in $response.