自己的开发路

PHP 杂

2018-05-15  本文已影响11人  冰镇苏打水

下载文件


身份证验证


is_null / empty / isset

is_null

empty

isset

变量 is_null empty isset
$a = '' false true true
$a = null true true false
var $a true true false
$a = array() false true true
$a = false false true true
$a = 15 false false true
$a = 1 false false true
$a = 0 false true true
$a = '0' false true true
$a = 'true' false false true
$a = 'false' false false true

PHP防止重复提交

    <?php
    session_start();
    header("Content-Type:text/html;charset=utf-8");
    function set_token()
    {
        $_SESSION['token'] = md5(microtime(true));
    }
    
    function valid_token()
    {
        $return = $_REQUEST['token'] === $_SESSION['token'] ? true : false;
        set_token();
        return $return;
    }
    
    if (!isset($_SESSION['token'])||$_SESSION['token'] === '') {
        set_token();
    }
    
    if (isset($_POST['web'])) {
        if (!valid_token()) {
            echo "token error, 请不要重复提交";
        }else{
            echo "成功提交, Value:".$_POST['web'];
        }
    }else{ ?>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>PHP防止重复提交表单</title>
    <meta name="keywords" content="PHP" />
    <meta name="description" content="PHP防止重复提交表单" />
    </head>
    <body>
    <div id="main">
      <div class="demo">
        <form method="post" action="">
          <input type="hidden" name="token" value="<?= $_SESSION['token']?>">
          <input type="text" class="input" name="web" value="重复测试">
          <input type="submit" class="btn" value="提交" />
        </form>
      </div>
    </div>
    </body>
    </html>
    <?php } ?>
上一篇下一篇

猜你喜欢

热点阅读