Home >Backend Development >PHP Tutorial >Analysis on the implementation method of PHP simulated login_PHP tutorial

Analysis on the implementation method of PHP simulated login_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:01:41753browse

Analysis of the implementation method of PHP simulated login

This article mainly introduces the implementation method of PHP simulated login. It analyzes the two implementation methods of snoopy and curl with examples, which has certain reference. Value, friends in need can refer to it

This article analyzes the implementation method of PHP simulated login through examples. Share it with everyone for your reference. The specific analysis is as follows:

How to implement simulated login in PHP. Here are two methods to implement simulated login on Renren.com. The specific example code is as follows:

1) Use snoopy to simulate login:

The code is as follows:

set_time_limit(0);
require "Snoopy.class.php";
$snoopy=new Snoopy();
$snoopy->referer='http://www.jb51.net/';
$snoopy->agent="Mozilla/5.0 (Windows NT 6.1; rv:22.0) Gecko/20100101 Firefox/22.0";
$submit_vars['email'] ='Login account';
$submit_vars['password'] ='Login password';
$url='http://www.jb51.net/test/Login.php';//URL address for login data submission
$snoopy->submit($url,$submit_vars);
$snoopy->fetch("http://www.jb51.net/");//The page data you want to get
echo $snoopy->results;//m.jb51.net
2) Use curl to simulate login:

The code is as follows:

set_time_limit(0);
$cookie_file=tempnam('./tmp','cookie');//The tmp directory needs to be created first
$ch=curl_init();
$login_url='http://www.jb51.net/PLogin.do';
$curlPost="email=login account&password=login password";
curl_setopt($ch,CURLOPT_URL,$login_url);
//When enabled, the header file information will be output as a data stream
curl_setopt($ch,CURLOPT_HEADER,0); //Set whether to output page content
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_POST,1); //Set the request sending method, post or get, CURLOPT_POST or CURLOPT_GET
curl_setopt($ch,CURLOPT_POSTFIELDS,$curlPost);
curl_setopt($ch,CURLOPT_COOKIEJAR,$cookie_file); //Save cookie
curl_exec($ch);
curl_close($ch);
$ch=curl_init();
$login_url2="http://www.jb51.net/";
curl_setopt($ch,CURLOPT_URL,$login_url2);
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,0);
curl_setopt($ch,CURLOPT_COOKIEFILE,$cookie_file); //Read cookie
curl_exec($ch);
curl_close($ch);

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/971920.htmlTechArticleAnalysis of the implementation method of php simulated login This article mainly introduces the implementation method of php simulated login, and analyzes snoopy with examples The two implementation methods with curl have certain reference value and require...
Statement:
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