Home > Backend Development > PHP Tutorial > Analysis of the implementation method of php simulated login, php simulated login implementation_PHP tutorial

Analysis of the implementation method of php simulated login, php simulated login implementation_PHP tutorial

WBOY
Release: 2016-07-13 10:10:00
Original
980 people have browsed it

Analysis of implementation method of php simulated login, implementation of php simulated login

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:

Copy code The code is as follows:
set_time_limit(0);
require "Snoopy.class.php";
$snoopy=new Snoopy();
$snoopy->referer='http://www.bkjia.com/';
$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.bkjia.com/test/Login.php';//URL address for login data submission
$snoopy->submit($url,$submit_vars);
$snoopy->fetch("http://www.bkjia.com/");//The page data you want to get
echo $snoopy->results;//m.jb51.net

2) Use curl to simulate login:
Copy code 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.bkjia.com/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.bkjia.com/";
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/940488.htmlTechArticleAnalysis of the implementation method of php simulated login, php simulated login implementation This article analyzes the implementation method of php simulated login. Share it with everyone for your reference. The specific analysis is as follows: PHP simulated 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