Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.