Jump to content

Posting a file to a site with curl


tibberous

Recommended Posts

Hi..

 

      made one page called "post.php"

 

<?php
//parameters for posting data
$data = array('var1' => 5,"var2"=>10);

// CURL Session initialization
$ch = curl_init();

//CURL Option settings
curl_setopt($ch, CURLOPT_URL,'http://localhost:9000/post_action.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

//execution and posting data
$res=curl_exec($ch);
echo "<pre>";
print_r($res);
?>

 

made another page called "post_action.php"

<?php
$res= $_POST['var1']+$_POST['var2'];
echo $res;
?>

 

now try to run post.php

you have summation of 2 vars posted in post.php in response.

 

Regards,

Vijay

 

 

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.