关键词搜索

源码搜索 ×
×

实例详解html的form表单和php的_POST数组,并用fiddler抓包来玩玩------走进Web、Server开发的世界

发布2017-08-05浏览10622次

详情内容

       在前面的文章中, 我们已经转载了Windows上搭建Apache, PHP和MySQL的方法, 我亲自试了一下, 非常好用! 本文, 我们只会用到Apache和PHP, 一起来看看。 


       在本地写test.html文件:

  1. <html>
  2. <body>
  3. <form action="http://localhost/index.php" method="post">
  4. 名字: <input type="text" name="name"><br>
  5. 邮箱: <input type="text" name="email"><br>
  6. <input type="submit">
  7. </form>
  8. </body>
  9. </html>
       然后在Apache关联的PHP目录下写php代码, index.php代码为:

  1. <?php
  2. echo "php ing <br />";
  3. $size = count($_POST);
  4. echo $size;
  5. echo "<br />";
  6. foreach($_POST as $key => $value)
  7. {
  8. echo $key . ":" . $value;
  9. echo "<br />";
  10. }
  11. $p = $_POST['name'].$_POST['email'];
  12. $s = "<script> alert('$p'); </script>";
  13. echo $s;
  14. echo "<br />";
  15. ?>
     当然, 你也可以写成更完整的代码(本质都一样), 如下:

  1. <html>
  2. <body>
  3. <?php
  4. echo "php ing <br />";
  5. $size = count($_POST);
  6. echo $size;
  7. echo "<br />";
  8. foreach($_POST as $key => $value)
  9. {
  10. echo $key . ":" . $value;
  11. echo "<br />";
  12. }
  13. $p = $_POST['name'].$_POST['email'];
  14. $s = "<script> alert('$p'); </script>";
  15. echo $s;
  16. echo "<br />";
  17. ?>
  18. </body>
  19. </html>

       我们双击test.html文件(实际上就是让浏览器打开test.html文件, 浏览器解析后, 就会得到下面的内容), 并在输入框内手动输入xxx和yyy, 如下:

         然后, 点击“提交”(实际上就是让浏览器发出http请求, 去触发Apache/PHP服务端的index.php文件的执行, 并把内容返回给客户端浏览器), 结果为:

        点击上述“确定”, 于是就有:

          

         如果进行fiddler抓包, 则有:


      点击“提交”时, 浏览器发出的http请求为:

POST http://localhost/index.php HTTP/1.1
Host: localhost
Connection: keep-alive
Content-Length: 18
Cache-Control: max-age=0
Origin: null
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.104 Safari/537.36 Core/1.53.3226.400 QQBrowser/9.6.11681.400
Content-Type: application/x-www-form-urlencoded
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.8

name=xxx&email=yyy
       

       其实, 一切已经一目了然了,  无需多说。 建议有兴趣的朋友, 都动手做做这些小实验, 抓包看看, 会有收获的。


       最后啰嗦一句, 简单来说, test.html是前台开发, index.php是后台开发。









相关技术文章

点击QQ咨询
开通会员
返回顶部
×
微信扫码支付
微信扫码支付
确定支付下载
请使用微信描二维码支付
×

提示信息

×

选择支付方式

  • 微信支付
  • 支付宝付款
确定支付下载