php實現類比登陸

來源:互聯網
上載者:User

標籤: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實現類比登陸

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.