码迷,mamicode.com
首页 > Web开发 > 详细

php实现模拟登陆

时间:2017-06-17 17:12:49      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:tags   content   返回   strip   验证   pos   name   title   header   

在不考虑验证码的情况一下,php实现模拟登陆,网上给的办法通常是採用curl来模拟实现,可是curl实现的是server端与server端建立了会话,仅仅能模拟登陆之后获取登陆之后的数据。无法将cookie信息种植到client上(至少眼下本人查找没有找到办法)最后自己通过隐藏的iframe来实现。

1、curl实现模拟登陆的代码,(仅仅是实现server与server建立会话,事实上并没有在client与server之间建立会话)

<?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>'; 
echo strip_tags($orders); 
echo '</pre>'; 
curl_close($ch2); 
?>
2、通过隐藏的iframe实现client与server端的通信(肯能带来一定的安全隐患)

<html>
<title></title>
<body>
<?

$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> </body> </html>


ceshi1.php

<html>
<head>
    <title>ceshi</title>
</head>
<body onload="get_pass1();">
<form name="form1" method="post" target="hiddenLoginFrame" action="http://<span style="font-family: Arial, Helvetica, sans-serif;">192.168.0.22</span><span style="font-family: Arial, Helvetica, sans-serif;">/logincheck.php"></span>
    <input type="text" value="admin" name="UNAME">
    <input type="text" value="123456" name="PASSWORD">
</form>
</body>
<script Language="JavaScript">
    function get_pass1()
    {
        //document.form1.action=u_url;
        document.form1.submit();
    }
</script>
</html>

php实现模拟登陆

标签:tags   content   返回   strip   验证   pos   name   title   header   

原文地址:http://www.cnblogs.com/jhcelue/p/7040515.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!