Posted By

CammoKing on 09/15/10


Tagged

curl


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

mmcachran


Send Curl


 / Published in: PHP
 

  1. // send some stuff
  2. $email = '[email protected]';
  3. $fName = 'John';
  4. $lName = 'Doe';
  5.  
  6. // set URL
  7. $url = 'http://www.domain.com/';
  8.  
  9. // set POST variables
  10. $fields = array(
  11. 'email'=>urlencode($email),
  12. 'first_name'=>urlencode($fName),
  13. 'last_name'=>urlencode($lName)
  14. );
  15. $fields_string='';
  16.  
  17. //url-ify the data for the POST
  18. foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
  19. rtrim($fields_string,'&');
  20.  
  21. //open connection
  22. $ch = curl_init();
  23.  
  24. //set the url, number of POST vars, POST data
  25. curl_setopt($ch,CURLOPT_URL,$url);
  26. curl_setopt($ch,CURLOPT_POST,count($fields));
  27. curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
  28.  
  29. //execute post
  30. $result = curl_exec($ch);
  31.  
  32. //close connection
  33. curl_close($ch);

Report this snippet  

You need to login to post a comment.