tags:

views:

78

answers:

4

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

+1  A: 
<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

DrColossos
+3  A: 
    <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
Babiker
+4  A: 

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.

Here's a pretty good walkthrough of both

jfoucher
+2  A: 

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.

Peter Anselmo
In as much as your solution is correct, I think the OP wanted to know how to do it with HTML form. Although the question was not very clear.
Helen Neely