Posted By

suibhne on 07/31/09


Tagged

curl php post


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

irishsk
umang_nine


PHP Curl Post


 / Published in: PHP
 

Simple PHP curl post.

  1. $url = "http://www.google.com";
  2. $ch = curl_init();
  3. curl_setopt($ch, CURLOPT_URL, $url); // set url to post to
  4. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
  5. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return into a variable
  6. curl_setopt($ch, CURLOPT_TIMEOUT, 3); // times out after 4s
  7. curl_setopt($ch, CURLOPT_POST, 1); // set POST method
  8. curl_setopt($ch, CURLOPT_POSTFIELDS, "url=index%3Dbooks&field-keywords=PHP+MYSQL"); // add POST fields
  9. $result = curl_exec($ch); // run the whole process
  10. curl_close($ch);
  11. echo $result;

Report this snippet  

You need to login to post a comment.