有没有一种方法可以限制php表单的提交数量?

编程入门 行业动态 更新时间:2024-10-26 08:26:34
本文介绍了有没有一种方法可以限制php表单的提交数量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

例如一张注册表只能使用x次?

eg. A registration form can only be used x amount of times?

推荐答案

PHP的快速而又肮脏的解决方案.

Quick and Dirty Solution For PHP.

每次他们访问页面时,它都会增加计数器的数量.太多次意味着页面die().您可以选择将此代码放置在仅当有人提交表单时才执行的位置.

Everytime they visit a page, it increments the counter. Too many times means the page die()s. You can choose to put this code in a spot where it will only be executed when someone submits the form.

它经常重置计数.

已知的错误:清除Cookie会破坏它,关闭cookie会破坏它.

Known Bugs: Clearing Cookies breaks it, having cookies off breaks it.

<?php session_start(); if(!isset($_SESSION['count'])) { $_SESSION['count'] = 1; $_SESSION['first'] = time(); } else { // Increase the Count $_SESSION['count']++; // Reset every so often if($_SESSION['first'] < (time() - 500)) { $_SESSION['count'] = 1; $_SESSION['first'] = time(); } // Die if they have viewed the page too many times if($_SESSION['count'] > 100) { die("You have submitted to many times"); } }

为您提供一个按用户的解决方案.如果是整个网站,请发表评论,然后删除.

This is given you want a per user solution. If it is a whole site thing, just comment and I'll delete.

更多推荐

有没有一种方法可以限制php表单的提交数量?

本文发布于:2023-11-23 19:33:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622628.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表单   数量   方法   php

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!