最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

PHP簡單實現(xiàn)模擬登陸功能示例

 更新時間:2017年09月15日 10:59:53   作者:PHP學習與交流  
這篇文章主要介紹了PHP簡單實現(xiàn)模擬登陸功能,涉及php使用curl實現(xiàn)模擬登陸的相關(guān)操作技巧,需要的朋友可以參考下

本文實例講述了PHP簡單實現(xiàn)模擬登陸功能。分享給大家供大家參考,具體如下:

在不考慮驗證碼的情況一下,php實現(xiàn)模擬登陸,網(wǎng)上給的辦法一般是采用curl來模擬實現(xiàn),但是curl實現(xiàn)的是服務(wù)器端與服務(wù)器端建立了會話,只能模擬登陸之后獲取登陸之后的數(shù)據(jù),無法將cookie信息種植到客戶端上(至少目前本人查找沒有找到辦法)最后自己通過隱藏的iframe來實現(xiàn)。

1、curl實現(xiàn)模擬登陸的代碼,(只是實現(xiàn)服務(wù)器與服務(wù)器建立會話,其實并沒有在客戶端與服務(wù)器之間建立會話)

<?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);
//設(shè)定返回的數(shù)據(jù)是否自動顯示
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//設(shè)定是否顯示頭信息
curl_setopt($ch, CURLOPT_HEADER, false);
//設(shè)定是否輸出頁面內(nèi)容
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實現(xiàn)客戶端與服務(wù)器端的通信(肯能帶來一定的安全隱患)

<html>
<title></title>
<body>
<?
$goURL="http://192.168.0.22/general/email/";
?>
<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://192.168.0.22/logincheck.php">
  <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>

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php curl用法總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《PHP數(shù)據(jù)結(jié)構(gòu)與算法教程》、《php程序設(shè)計算法總結(jié)》、《php字符串(string)用法總結(jié)》及《php常見數(shù)據(jù)庫操作技巧匯總

希望本文所述對大家PHP程序設(shè)計有所幫助。

相關(guān)文章

最新評論

垦利县| 石狮市| 民丰县| 额敏县| 绥宁县| 大同市| 依兰县| 高唐县| 黔西县| 江川县| 渭南市| 镇远县| 白银市| 黑河市| 铁岭县| 江西省| 漠河县| 余姚市| 独山县| 麻城市| 九江县| 乌兰察布市| 贵州省| 肇州县| 祁门县| 五台县| 永平县| 无棣县| 定襄县| 韩城市| 永州市| 陈巴尔虎旗| 新晃| 四会市| 莆田市| 滦南县| 三亚市| 鹤岗市| 华蓥市| 庐江县| 县级市|