Home > php教程 > php手册 > php模拟登陆的实现方法

php模拟登陆的实现方法

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 09:20:10
Original
1755 people have browsed it

php模拟登陆的实现方法

php模拟登陆的实现方法,这里分别列举两种方法实现模拟登陆人人网。具体实例代码如下:

(1)使用snoopy模拟登陆

<?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)使用curl模拟登陆

<?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

您可能感兴趣的文章

  • php模拟post请求的方法总结
  • PHP 异步执行方法,模拟多线程
  • php模拟ping命令的方法
  • 如何设置phpmyadmin自动登陆和取消自动登录
  • php模拟发送get请求
  • phpmyadmin如何设置自动登陆
  • php分别模拟发送GET和POST请求
  • php window平台模拟checkdnsrr函数检测email是否真实存在
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template