Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How php restricts users to submit only once

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article will explain in detail how php limits users to submit only once. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

Php limits the implementation method that users can only submit once: 1, through "$ip=getenv ('REMOTE_ADDR');" to obtain ip, and use ip to limit; 2, save an one-day COOKIE in the client browser.

This article operating environment: Windows7 system, PHP7.1 version, Dell G3 computer.

Php limits the number of post, for example, you can only post once a day:

First, if you use IP restrictions, you can only get the extranet IP of the other user, then the IP of all computers in the Internet bar is the same, and only one computer in this Internet bar can be submitted in one day. If your customers are mainly home users, you can use IP restrictions, otherwise IP restrictions will limit a lot of innocent people.

How to get the IP:

$ip=getenv ('REMOTE_ADDR')

IP restrictions can still be broken, home broadband users cut off to redial, will get a new IP.

Once again, the server cannot obtain an intranet IP address such as 192.1.1.100.

Second, in addition to IP, you can also use COOKIE restrictions to save a COOKIE valid for one day in the client browser, and the program detects COOKIE to limit it. This method can solve the problem that IP restrictions are too strict on Internet cafes, but it cannot solve the problem of smart customers clearing browser COOKIE by themselves.

How to set the COOKIE valid for one day:

Setcookie ("TestCookie", $value, time () + 2403600)

Both of the above methods have their own advantages, and you can combine them to make a slightly more reasonable one, but neither can be perfect.

This is the end of the article on "how to limit users to submit once by php". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report