欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP實(shí)現(xiàn)防止表單重復(fù)提交功能【基于token驗(yàn)證】

 更新時(shí)間:2018年05月24日 11:34:27   作者:請叫我郝先生  
這篇文章主要介紹了PHP實(shí)現(xiàn)防止表單重復(fù)提交功能,結(jié)合實(shí)例形式分析了php基于token驗(yàn)證防止表單重復(fù)提交的相關(guān)操作技巧,非常簡單實(shí)用,需要的朋友可以參考下

本文實(shí)例講述了PHP實(shí)現(xiàn)防止表單重復(fù)提交功能。分享給大家供大家參考,具體如下:

防止表單重復(fù)提交的方法有很多種,那么今天就給大家介紹一種php如何有效的防止表單重復(fù)提交。

代碼非常簡單

我相信大家很聰明給大家分享一個(gè)小的demo,大家可以借鑒一下:

具體代碼:

<?php
/*
* 2016年9月29日08:09:13
*/
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;
}
//如果token為空則生成一個(gè)token
if(!isset($_SESSION['token']) || $_SESSION['token']=='') {
  set_token();
}
if(isset($_POST['web'])){
  if(!valid_token()){
    echo "token error,請不要重復(fù)提交!";
  }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防止重復(fù)提交表單</title>
<meta name="keywords" content="PHP" />
<meta name="description" content="PHP防止重復(fù)提交表單" />
</head>
<body>
<div id="main">
  <div class="demo">
    <form method="post" action="">
      <input type="hidden" name="token" value="<?php echo $_SESSION['token']?>">
      <input type="text" class="input" name="web" value="腳本之家">
      <input type="submit" class="btn" value="提交" />
    </form>
  </div>
</div>
</body>
</html>
<?php }?>

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php程序設(shè)計(jì)安全教程》、《php安全過濾技巧總結(jié)》、《PHP基本語法入門教程》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總

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

相關(guān)文章

最新評論