Jump to content

Using cURL to send POST requests


BRUm

Recommended Posts

Hello,

 

I'm trying to use curl_init() and curl_setopt() to send some data via POST to another script where it will be parsed.

 

This script is basic, yet I don't understand why it's not working. My experience with cURL functions is little.

 

Here's the main script which sends the data:

 

<?

$path = "form.php"; //Relative path to the file with $_POST parsing
$ch = curl_init($path); //Initialise curl resource with above file
$data = "submit=submit&name=bob&age=100"; //Data to be sent to the file
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); //Send the data to the file?
curl_close($ch); //Close curl session

?>

 

Here's the recipient script which parses the request, and on success should make a directory named "success". I have tested the directory creation without the first script, as I thought it may be permission problems, however everything in that area is fine.

 

<?

if($_POST['submit'])
       {
print "Your name is ".$_POST['name']." and your age is ".$_POST['age'];
mkdir("C:/Users/Lee/Desktop/xampp/htdocs/PHP/".$_POST['name']);
}

?>

 

When executing the first script I receive noting but a blank screen. I tried curl_exec($ch); to generate some output yet it gave nothing of use.

 

Any help would be greatly appreciated.

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/67273-using-curl-to-send-post-requests/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.