Home > php教程 > php手册 > php中如何防止表单的重复提交

php中如何防止表单的重复提交

WBOY
Release: 2016-06-13 11:42:27
Original
1042 people have browsed it

复制代码 代码如下:


/*
 * php中如何防止表单的重复提交
 */
session_start();
if (empty($_SESSION['ip'])) {//第一次写入操作,判断是否记录了IP地址,以此知道是否要写入数据库
    $_SESSION['ip'] = $_SERVER['REMOTE_ADDR']; //第一次写入,为后面刷新或后退的判断做个铺垫
    //...........//写入数据库操作
} else {//已经有第一次写入后的操作,也就不再写入数据库
    echo '请不要再次刷新和后退'; //写一些已经写入的提示或其它东西
}
?>


还有办法就是:
1、在页面生成随机码,也就是每次提交随机码都不一样,在提交的时候验证随机码!
2、在提交的时候,验证如果数据存在,就不提交了.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template