PHP through Curl Add cookies to forge landing crawl data methods _php tips

Source: Internet
Author: User
Tags curl

The example in this article describes the way in which PHP uses Curl to spoof landing crawl data by adding cookies. Share to everyone for your reference, specific as follows:

Some Web pages must be logged to see, this time want to crawl information must be in the header pass the cookie value to get

1, the first landing site, open Firebug can see the corresponding cookies to copy these cookies can be used

2,

 <?php header ("content-type:text/html;
Charset=utf8 ");
$ch =curl_init ();
curl_setopt ($ch, Curlopt_url, ' http://www.babytree.com/user/picjournal.php ');
$header = Array ();
curl_setopt ($ch, curlopt_post,true);
curl_setopt ($ch, Curlopt_postfields, $fields);
curl_setopt ($ch, curlopt_returntransfer,true);
curl_setopt ($ch, curlopt_header,true);
curl_setopt ($ch, Curlopt_httpheader, $header); curl_setopt ($ch, Curlopt_cookie, ' b=115.100.62.7.1401937092035530; bdshare_firstime=1401937092199; __myutma=
122328856.1548793539.1401937093.1408503164.1408694138.69; ');
$content = curl_exec ($ch);
echo "<pre>";p Rint_r (Curl_error ($ch)); echo "</pre>";
echo "<pre>";p Rint_r (Curl_getinfo ($ch)); echo "</pre>";
echo "<pre>";p Rint_r ($header); echo "</pre>";

echo "</br>", $content; 

More interested in PHP related content readers can view the site topics: "Php Curl Usage Summary", "PHP operation and operator Usage Summary", "PHP Network Programming Skills Summary", "PHP Basic Grammar Introductory Tutorial", "PHP operation Office Document skills Summary (including Word, Excel,access,ppt), "The PHP date and time usage summary", "PHP object-oriented Programming Introduction Tutorial", "PHP string (String) Usage Summary", "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation skill Summary"

I hope this article will help you with the PHP program design.

Related Article

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.