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

最新文章

  1. WPF入门:XAML
  2. 【原】Python用例:将指定文件或目录打包成zip文件
  3. linux标准io的copy
  4. 在windows下新建maven项目
  5. poj邮局1160
  6. 什么是USBMini接口
  7. 10+ commonly using find command switches with example Unix/Linux
  8. 关于触发器、存储过程和DBlink的综合运用 (转)
  9. php基础(三)超全局变量
  10. Python之列表&amp;元组&amp;字典
  11. Github+Hexo搭建静态博客
  12. 笔记:XML-解析文档
  13. JAVA中时间格式(SimpleDateFormat)和数字格式(DecimalFormat)转换详解(转)
  14. issue_hana
  15. Echarts学习求教
  16. Best Practices in Asynchronous Programming
  17. [dpdk] 使用pktgen生成tcp三次握手的测试流量
  18. (转) JVM Crash with SIGSEGV - problematic frame - libzip.so
  19. C/C++求职宝典21个重点笔记(常考笔试面试点)
  20. 贪心算法: Codevs 1052 地鼠游戏

热门文章

  1. 简洁的MVC思想框架——Nancy(Post操作与外部引用css和JS)
  2. URL正则
  3. centos安装nvidia驱动
  4. BZOJ 2119 股市的预测(后缀数组)
  5. LAMP环境搭建备忘 -- MariaDB 安装(三)
  6. 为什么不能往Android的Application对象里存储数据
  7. LoadRunner使用入门 进行Webservice负载測试
  8. hadoop1.1.0的伪分布搭建步骤
  9. 安装xcode6 beta 后调试出现Unable to boot the iOS Simulator以及编译苹果官方Swift的demo报错failed with exit code 1的解决的方法
  10. 软件project之软件设计