Use the PHP curl function to simulate post to obtain the content

Source: Internet
Author: User
  1. <? PHP
  2. //--------------------------------------------------------------------------
  3. // File name: curl_post.php
  4. // File Description: simulates post using PHP's curl function. It supports simulating cookies and useragent.
  5. // Source code Author: lone soul (www.kalvin.cn)
  6. //--------------------------------------------------------------------------
  7. // Replace the http://www.kalvin.cn/index.php in $ URL with your post address
  8. $ URL='Http: // www.kalvin.cn/index.php';
  9. // Target Source Page
  10. $ Referer='Http: // www.kalvin.cn /';
  11. // If you need to log on to the target website, you can write the simulated cookie value here.
  12. $ Cookie='';
  13. // Write $ post_data into your intercepted data packets. You can use Winsock Expert to intercept data packets.
  14. $ Post_data='Author = soul & date = 2008.06.04';
  15. // Some websites verify the browser information. You can simulate the browser below and copy the useragent directly to it.
  16. $ Useragent='';
  17. // The following content cannot be modified
  18. $ Ch= Curl_init ();
  19. Curl_setopt ($ Ch, Curlopt_post, 1 );
  20. Curl_setopt ($ Ch, Curlopt_header, 0 );
  21. Curl_setopt ($ Ch, Curlopt_url,$ URL);
  22. Curl_setopt ($ Ch, Curlopt_referer,$ Referer);
  23. Curl_setopt ($ Ch, Curlopt_postfields,$ Post_data);
  24. Curl_setopt ($ Ch, Curlopt_cookie,$ Cookie);
  25. Curl_setopt ($ Ch, Curlopt_useragent,$ Useragent);
  26. $ Result= Curl_exec ($ Ch);
  27. ?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.