Home > Backend Development > PHP Tutorial > php实现模拟登陆

php实现模拟登陆

WBOY
Release: 2016-06-23 13:42:58
Original
753 people have browsed it

在不考虑验证码的情况一下,php实现模拟登陆,网上给的办法一般是采用curl来模拟实现,但是curl实现的是服务器端与服务器端建立了会话,只能模拟登陆之后获取登陆之后的数据,无法将cookie信息种植到客户端上(至少目前本人查找没有找到办法)最后自己通过隐藏的iframe来实现。

1、curl实现模拟登陆的代码,(只是实现服务器与服务器建立会话,其实并没有在客户端与服务器之间建立会话)

<?php $cookie_jar = tempnam('./tmp','cookie');$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://192.168.0.22/logincheck.php');curl_setopt($ch, CURLOPT_POST, 1); $request = 'UNAME=admin&PASSWORD=123456';curl_setopt($ch, CURLOPT_POSTFIELDS, $request); //把返回来的cookie信息保存在$cookie_jar文件中 curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_jar); //设定返回的数据是否自动显示 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //设定是否显示头信息 curl_setopt($ch, CURLOPT_HEADER, false); //设定是否输出页面内容 curl_setopt($ch, CURLOPT_NOBODY, false); curl_exec($ch); curl_close($ch);//get data after login $ch2 = curl_init(); curl_setopt($ch2, CURLOPT_URL, 'http://192.168.0.22/general/');curl_setopt($ch2, CURLOPT_HEADER, false); curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch2, CURLOPT_COOKIEFILE, $cookie_jar); $orders = curl_exec($ch2);echo $orders;exit;echo '<pre class="brush:php;toolbar:false">'; echo strip_tags($orders); echo '
Copy after login
'; curl_close($ch2); ?>2、通过隐藏的iframe实现客户端与服务器端的通信(肯能带来一定的安全隐患)

<title></title>$goURL="http://<span style="font-family: Arial, Helvetica, sans-serif;">192.168.0.22</span><span style="font-family: Arial, Helvetica, sans-serif;">/general/email/";</span>?><iframe name="hiddenLoginFrame" onload="get_pass()" src="ceshi1.php" id="hiddenLoginFrame" width="0" height="0" frameborder="0" scrolling="no" style="display:none;"></iframe><script language="JavaScript">    function get_pass()    {        window.open("<?=$goURL ?>");        window.close();    }</script>
Copy after login

ceshi1.php

    <title>ceshi</title>
Copy after login
192.168.0.22/logincheck.php">

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