Home > Backend Development > PHP Tutorial > Detailed explanation of methods and examples of php adding cookies to forge login and capture data through curl

Detailed explanation of methods and examples of php adding cookies to forge login and capture data through curl

墨辰丷
Release: 2023-03-29 17:12:01
Original
1914 people have browsed it

This article mainly introduces the method of PHP adding cookies through curl to forge login and capture data. It involves related skills of PHP operating cookies and page crawling based on curl. Friends in need can refer to the example of this article

Describes how PHP uses curl to add cookies to forge login and capture data. Share it with everyone for your reference, the details are as follows:

Some web pages must be logged in to see. At this time, if you want to grab the information, you must pass the cookie value in the header to get it

1. First of all Log in to the website, open firebug and you will see the corresponding cookies. Copy these cookies and you can use them.

2,

<?php
header("Content-type:text/html;Charset=utf8");
$ch =curl_init();
curl_setopt($ch,CURLOPT_URL,&#39;http://www.babytree.com/user/picjournal.php&#39;);
$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,&#39;B=115.100.62.7.1401937092035530; bdshare_firstime=1401937092199; __myutma=122328856.1548793539.1401937093.1408503164.1408694138.69;&#39;);
$content = curl_exec($ch);
echo "<pre class="brush:php;toolbar:false">";print_r(curl_error($ch));echo "
"; echo "
";print_r(curl_getinfo($ch));echo "
"; echo "
";print_r($header);echo "
"; echo "
",$content;
Copy after login

Summary: The above is this article The entire content of this article is hoped to be helpful to everyone's study.

Related recommendations:

The method of subclass overloading the parent class in PHP (parent::method name)

PHP encapsulated MSSql operation class and complete example analysis

phpHow to connect to oracle database and simple analysis

The above is the detailed content of Detailed explanation of methods and examples of php adding cookies to forge login and capture data through curl. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template