Home > headlines > PHP obtains (curl) web page data collection method with cookies

PHP obtains (curl) web page data collection method with cookies

PHP中文网
Release: 2018-05-15 13:54:27
Original
10517 people have browsed it

This morning, the editor opened our PHP Chinese website (m.sbmmt.com) and saw that some netizens were asking PHP to obtain page data. They need to bring cookies. They don’t know how to write it. Our website’s full-time engineers responded immediately. And gave a solution. Here I share it with everyone to learn how to obtain web page data in PHP. Below is the original question from a netizen.

php get Web page data I want to write a web page data collection with cookies. I don’t know how to write it in PHP. Is there any expert who can give me an answer? Collection URL = “https://steamcommunity.com/tradeoffer/new /partnerinventory/?sessionid=29475e48124c520cf70060dc&partner=76561198124311480&appid=433850&contextid=1”

cookie="sessionid=29475e48124c520cf70060dc;steamLoginSecure=765 61198117047952%7C%7C512C7DB04B6A9719E1673019C075AA5ECF2B5032"
Can you write an example with explanation? Thank you. This cookie has a time limit. If it expires, just write an example.

Our staff provides the use of CURL to violate the COOKIE. You can read the next step. Regarding the types of curl-php Chinese website provides many types of downloads //m.sbmmt.com/xiazai/leiku/curl

<?php
error_reporting(E_ALL);
ini_set(&#39;display_errors&#39;,&#39;1&#39;);
ignore_user_abort();
set_time_limit(0);
$cookie_path=&#39;./&#39;;
$vars[&#39;username&#39;]=&#39;wang&#39;;
$vars[&#39;password&#39;]=&#39;123456&#39;;
$method_post=true;
$url=&#39;http://ceshi.php.cn/user/usertop_login.asp&#39;;
$ch=curl_init();
$params[CURLOPT_URL]=$url;
$params[CURLOPT_HEADER]=0;//是否显示http头信息
$params[CURLOPT_RETURNTRANSFER]=true;
$params[CURLOPT_FOLLOWLOCATION]=0;
$params[CURLOPT_USERAGENT]=&#39;Mozilla/5.0 (Windows NT 6.1; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0&#39;;
//$params[CURLOPT_SSL_VERIFYPEER]=false;
//$params[CURLOPT_SSL_VERIFYHOST]=false;
$postfields=&#39;&#39;;
foreach($vars as $k=>$v){
    $postfields.=urlencode($k).&#39;=&#39;.urlencode($v).&#39;&&#39;; 
}
$params[CURLOPT_POST]=true;
$params[CURLOPT_POSTFIELDS]=$postfields;
if(isset($_COOKIE[&#39;cookie_jar&#39;]) && ($_COOKIE[&#39;cookie_jar&#39;] || is_file($_COOKIE[&#39;cookie_jar&#39;]))){
    $params[CURLOPT_COOKIEFILE]=$_COOKIE[&#39;cookie_jar&#39;];
}else{
    $cookie_jar=tempnam($cookie_path,&#39;cookie&#39;);//产生一个cookie文件
    $params[CURLOPT_COOKIEJAR]=$cookie_jar;//写入cookie信息
    setcookie(&#39;cookie_jar&#39;,$cookie_jar);//保存cookie路径
}
curl_setopt_array($ch,$params);
$content=curl_exec($ch);
//var_dump(strip_tags($content));
  
//第二步
$params[CURLOPT_FOLLOWLOCATION]=true;
$nexturl=&#39;http://ceshi.php.cn/user/vpsadm2.asp?id=100568&go=c&#39;;
$params[CURLOPT_URL]=$nexturl;
$params[CURLOPT_POSTFIELDS]=&#39;&#39;;
curl_setopt_array($ch,$params);
$content=curl_exec($ch);
sleep(5);
 
//第三步
$nexturl=&#39;http://ceshi.php.cn/vpsadm/selfvpsmodifyendtime.asp&#39;;
$params[CURLOPT_URL]=$nexturl;
$params[CURLOPT_POSTFIELDS]=&#39;year=9001&moneynow=10&id=100568&&#39;;
curl_setopt_array($ch,$params);
$content=curl_exec($ch);
echo strip_tags($content);
  
curl_close($ch);
Copy after login
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