php通过session判断防止表单重复提交实例,当用户提交表单后,为防止重复操作,通过session来判断是否为初次提交,否则让他返回到之前表单页面。

当前表单页面is_submit设为0 (推荐学习:PHP视频教程)
SESSION_START();
$_SESSION['is_submit'] = 0;
<form id="reg" action="post.php" method="post">
<p>用户名:<input type="text" class="input" name="username" id="user"></p>
<p>密 码:<input type="password" class="input" name="password" id="pass"></p><p><span>立即学习</span>“<a href="https://pan.quark.cn/s/7fc7563c4182" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">PHP免费学习笔记(深入)</a>”;</p>
<div class="aritcle_card">
<a class="aritcle_card_img" href="/xiazai/code/11167">
<img src="https://img.php.cn/upload/webcode/000/000/020/176519340224613.jpg" alt="游戏点卡API接口">
</a>
<div class="aritcle_card_info">
<a href="/xiazai/code/11167">游戏点卡API接口</a>
<p>点卡API支付接口支持各大游戏类一卡通接口。优势:1、同行业点卡回收支付业务更全;2、同行业点卡回收处理速度更快;3、同行业点卡回收技术更强,支持多卡同时提交;更新内容:1、增加点卡卡密规则文档,发便开发人员根据卡密位数提交前判断;2、增加点卡api接口密钥申请教程,减少在申请过程担误的时间;3、POST传值加密措施更严谨,同行业内存在多年的不足已修复完善;</p>
<div class="">
<img src="/static/images/card_xiazai.png" alt="游戏点卡API接口">
<span>0</span>
</div>
</div>
<a href="/xiazai/code/11167" class="aritcle_card_btn">
<span>查看详情</span>
<img src="/static/images/cardxiayige-3.png" alt="游戏点卡API接口">
</a>
</div>
<p>E-mail:<input type="text" class="input" name="email" id="email"></p>
<p><input type="submit" name="submit" class="btn" value="提交注册"/></p>
</form>是提交表单了,设当前'is_submit为1,若是刷新post.php,那么将执行else代码
SESSION_START();
if (isset($_POST['submit'])) {
if ($_SESSION['is_submit'] == '0') {
$_SESSION['is_submit'] = '1';
echo "代码块,要做的事,代码...<a onclick='history.go(-1);' href='javascript:void(0)'>返回</a>";
} else {
echo "请不用重复提交<a href='index.php'>PHP+SESSION防止表单重复提交</a>";
}
}以上就是php接口怎么判断重复提交的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号