Implementation method of php simulated login_PHP tutorial

WBOY
Release: 2016-07-13 10:12:54
Original
1196 people have browsed it

How to implement php simulated login

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

(1) Use snoopy to simulate login

<?php
set_time_limit(0);
require "Snoopy.class.php";
$snoopy=new Snoopy();
$snoopy->referer='http://www.renren.com/';
$snoopy->agent="Mozilla/5.0 (Windows NT 6.1; rv:22.0) Gecko/20100101 Firefox/22.0";
$submit_vars['email'] ='登陆账号';
$submit_vars['password'] ='登陆密码';
$url='http://www.renren.com/PLogin.do';//登陆数据提交的URL地址
$snoopy->submit($url,$submit_vars);
$snoopy->fetch("http://www.renren.com/");//希望获取的页面数据
echo $snoopy->results;//www.phpernote.com
Copy after login

(2) Use curl to simulate login

<?php
set_time_limit(0);
$cookie_file=tempnam('./tmp','cookie');//tmp目录需要先建立好
$ch=curl_init();
$login_url='http://www.renren.com/PLogin.do';
$curlPost="email=登陆账号&password=登陆密码";
curl_setopt($ch,CURLOPT_URL,$login_url);
//启用时会将头文件的信息作为数据流输出
curl_setopt($ch,CURLOPT_HEADER,0); //设定是否输出页面内容
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_POST,1); //设置请求发送方式,post或get,CURLOPT_POST或CURLOPT_GET
curl_setopt($ch,CURLOPT_POSTFIELDS,$curlPost);
curl_setopt($ch,CURLOPT_COOKIEJAR,$cookie_file); //保存cookie
curl_exec($ch);
curl_close($ch);

$ch=curl_init();
$login_url2="http://www.renren.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); //读取cookie
curl_exec($ch);
curl_close($ch);
Copy after login

Articles you may be interested in

  • Summary of methods for php simulated post requests
  • PHP asynchronous execution method, simulated multi-threading
  • php simulation Method of ping command
  • How to set up automatic login and cancel automatic login in phpmyadmin
  • php simulates sending a get request
  • How to set up automatic login in phpmyadmin
  • php simulates respectively Send GET and POST requests
  • php window platform simulates the checkdnsrr function to detect whether the email actually exists

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/918384.htmlTechArticleHow to implement php simulated login. How to implement php simulated login. Here are two methods to implement simulated login for everyone. net. The specific example code is as follows: (1) Use snoopy to simulate 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