zoukankan      html  css  js  c++  java
  • php实现模拟登陆

    在不考虑验证码的情况一下,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>

  • 相关阅读:
    [总结] XPO (eXpress Persistent Objects) 学习总结一
    [总结]工作中常用的正则表达式,有了它事半功倍!
    用JS实现页面滚动位置保持的方法
    [总结]TLF论坛全功略,下载指南!
    Javascript里使用Dom操作Xml
    。NET构架相关资源
    [收藏]关于用Asp.Net论坛发帖软件的实现
    匹配Unicode字符的正则表达式(中文)
    [转贴]如何实现TreeView的双击事件?
    [转贴]客户端不装adobe reader,打开pdf文件的插件
  • 原文地址:https://www.cnblogs.com/jhcelue/p/7040515.html
Copyright © 2011-2022 走看看