以前讲述的都是利用js来防止用户重复提交数据,但是如果用户利用机器你的js就没有一点办法防止用户重复提交数据了,下面我来介绍php防止重复提交数据程序。
利用session来操作
代码如下 | 复制代码 |
session_start(); |
利用cookie来解决
提交页面代码如下a.php代码如下:
代码如下 | 复制代码 |
php
代码如下 | 复制代码 |
setcookie("onlypost", 't'); //设置cookie,可以带上时间值。像有些论坛防止灌水就可以将你的一些基本信息存放到里面。 ?> |
处理页面b.php代码如下:
代码如下 | 复制代码 |
if($_COOKIE['onlypost'] == 't'){ print_r($_COOKIE); //处理提交的内容 如果验证成功则处理 print "ok"; setcookie("onlypost", 'f'); //改变cooike值删除也可以了 |

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 English version
Recommended: Win version, supports code prompts!

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool
