Blogger Information
Blog 49
fans 0
comment 4
visits 41890
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
get和post请求与传统的表单验证(时间:2019年1月19 1:00)
过儿的博客
Original
969 people have browsed it

两种请求类型:get和post

二者的区别:get就是客户端从服务器上获取资源,典型的读操作,不会对服务器数据有任何影响。通常GET请求时会带上用户的请求参数作为条件,这些参数会以?开始的键值对方式出现在URL地址中。

        post请求:本意是“发布”,用户将内容提交到服务器上进行发布,典型的写操作,会影响到服务器数据。post请求的数据量比较大,信息也比较敏感,不适合在URL中。

实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>get和post的区别,传统验证</title>
</head>
<body>
    <h2>用户登录</h2>
    <form action="admin/check.php" method="POST">
      <p>
          <label for="email">邮箱:</label>
          <input type="email" name="email" id="name">
      </p>
      <p>
          <label for="password">密码:</label>
          <input type="password" name="password" id="password">
      </p>
      <p><button>登录</button></p>
    </form>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例

传统验证文件

实例

<?php
if($_SERVER['REQUEST_METHOD'] == 'POST'){
    $emailList = ['admin@php.cn','peter@php.cn'];
    $info = '';
    if(empty($_POST['email'])){
        exit('<script>alert("邮箱不能为空");history.back();</script>');
    }elseif(!in_array($_POST['email'],$emailList)){
        exit('<script>alert("新用户,请先注册");location.href="register.php";</script>')
    }

    if(empty($_POST['password'])){
        exit('<script>alert("密码不能为空");history.back();</script>');
    }
    if($_POST['email'] && $_POST['password']){
        echo '<script>alert("验证通过,登录成功");location.href="index.php";</script>';
    }
}
?>

运行实例 »

点击 "运行实例" 按钮查看在线实例

1.png

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post