Before processing and saving data, first determine how the browser obtains the page. Use the $_SERVER
["REQUEST_METHOD"] variable to get the browser's method of obtaining the page. Check if it is "POST". Use session in the
script to record whether the user submits data through normal channels (i.e., the page where the submission content is filled in). Or use $_SERVER["HTTP_REFERER"] to detect this, but this is not recommended. Because some browsers
do not have REFERER set, some firewalls will also block REFERER. In addition, we also need to check the submitted content to see if there is duplicate content in the database. Take the guestbook as an example, use Session to determine:
In the page where you fill in the browsing content, we add at the front end:
$_SESSION["allowgbookpost"]=time(); //The time when filling in the registration
In the page that accepts message data and saves it, we also use Session before data processing
The following processing:
if(strtoupper($_SERVER["REQUEST_METHOD"])!=”POST”) { die("Error: Please do not submit externally."); } //Check whether the page acquisition method is POST
if(!isset($_SESSION["allowgbookpost"]) or
(time ()-$_SESSION["allowgbookpost"] < 10)){ die("Error: Do not submit externally.
"); } //Check the time when the message was filled in
if(isset($ _SESSION["gbookposttime"]) and
(time()-$_SESSION["gbookposttime"] < 120)){ die("Error: The interval between two submissions must not be less than 2 minutes. "); } //Check the message interval
unset($_SESSION["allowgbookpost"]); //Unregister the allowgbookpost variable to prevent
entering the filling page multiple times and submitting multiple times
$_SESSION["gbookposttime "]=time(); //Register the time to send messages to prevent spamming or malicious attacks
...
Data processing and storage
...
The above introduces how to prevent screen spam in PHP, including some aspects. I hope it will be helpful to friends who are interested in PHP tutorials.
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