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