老大,小弟有些迷惑的东西
请教各位老大,小弟有些迷惑的东西。
小弟的系统(一个cms)中有个搜索页面是这样的 以下代码是为了防止用户频繁的搜索
$lockfile = './time.lock.inc'; //time.lock.inc 内容为: 1337659312
$lasttime = file_get_contents($lockfile);
if(!empty($lasttime) && ($lasttime + $cfg_search_time) > time())
{
ShowMsg('请勿频繁操作','-1');
exit();
}
每次搜索完后会更新当前的时间到 time.lock.inc
这段代码其实是防止了所有的用户在指定$cfg_search_time内不能同时进行2次以上的操作,但是这样肯定不妥。
原因如下(不知是否妥当),请各位老大帮忙分析分析:
假如$cfg_search_time=1 同时有20人在并发搜索 理想情况中间不乱费一丝时间(服务器及网速消耗时间忽略不计)需要20秒
因为是这样 我想做下改进 在time.lock.inc存储2个信息 一个IP 一个时间戳
$dataiplist0=>array('14.453.22.55'=>1337659312,...);
?>
然后每次都获取一次IP 在每次搜索的时候针对指定IP来进行检测 同一IP1秒之内只能搜索一次,这样就可以并发搜索了,但是这里就有个问题 假如一个内网段的用户都是用同一个外网IP上网,这样就可能将整个内网都当成一个用户在处理了,不知道这些问题各位大哥遇到过没,怎么处理。
最后弱弱的问下,这样能有效的控制用户恶意骚扰吗,如果不能,各位大大是否能给个好的建议。。。
------解决方案--------------------
保存array到这个文件,
以session id为key,值为上次搜索的时间戳。
------解决方案--------------------
这样子,因为搜索的人应该不会很多,当然个别(动作)论坛除外
可以使用memcache 来保存数据
用ip+用户名+搜索时间的组合方式来判断
------解决方案--------------------
你一开始的锁定是针对所有用户的,所以用文件锁是正确的
后来你又想只锁定单个用户,那么用 session 就可以了
------解决方案--------------------
session控制即可, 如果要防黑客另当别论, session对它们毫无作用, 不提交cookie就是了.
------解决方案--------------------
新建一表,把搜索的用户放进去。判断是否有记录或者时间在一定范围内。就不让再查了

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Solution to the problem that the php session disappears after refreshing: 1. Open the session through "session_start();"; 2. Write all public configurations in a php file; 3. The variable name cannot be the same as the array subscript; 4. In Just check the storage path of the session data in phpinfo and check whether the sessio in the file directory is saved successfully.

The problem was found in the springboot project production session-out timeout. The problem is described below: In the test environment, the session-out was configured by changing the application.yaml. After setting different times to verify that the session-out configuration took effect, the expiration time was directly set to 8 hours for release. Arrived in production environment. However, I received feedback from customers at noon that the project expiration time was set to be short. If no operation is performed for half an hour, the session will expire and require repeated logins. Solve the problem of handling the development environment: the springboot project has built-in Tomcat, so the session-out configured in application.yaml in the project is effective. Production environment: Production environment release is

Session failure is usually caused by the session lifetime expiration or server shutdown. The solutions: 1. Extend the lifetime of the session; 2. Use persistent storage; 3. Use cookies; 4. Update the session asynchronously; 5. Use session management middleware.

Solution to the cross-domain problem of PHPSession In the development of front-end and back-end separation, cross-domain requests have become the norm. When dealing with cross-domain issues, we usually involve the use and management of sessions. However, due to browser origin policy restrictions, sessions cannot be shared by default across domains. In order to solve this problem, we need to use some techniques and methods to achieve cross-domain sharing of sessions. 1. The most common use of cookies to share sessions across domains

The default expiration time of session PHP is 1440 seconds, which is 24 minutes, which means that if the client does not refresh for more than 24 minutes, the current session will expire; if the user closes the browser, the session will end and the Session will no longer exist.

Problem: Today, we encountered a setting timeout problem in our project, and changes to SpringBoot2’s application.properties never took effect. Solution: The server.* properties are used to control the embedded container used by SpringBoot. SpringBoot will create an instance of the servlet container using one of the ServletWebServerFactory instances. These classes use server.* properties to configure the controlled servlet container (tomcat, jetty, etc.). When the application is deployed as a war file to a Tomcat instance, the server.* properties do not apply. They do not apply,

1. Implementing SMS login based on session 1.1 SMS login flow chart 1.2 Implementing sending SMS verification code Front-end request description: Description of request method POST request path /user/code request parameter phone (phone number) return value No back-end interface implementation: @Slf4j@ ServicepublicclassUserServiceImplextendsServiceImplimplementsIUserService{@OverridepublicResultsendCode(Stringphone,HttpSessionsession){//1. Verify mobile phone number if

JavaScriptCookies Using JavaScript cookies is the most effective way to remember and track preferences, purchases, commissions and other information. Information needed for a better visitor experience or website statistics. PHPCookieCookies are text files that are stored on client computers and retained for tracking purposes. PHP transparently supports HTTP cookies. How do JavaScript cookies work? Your server sends some data to your visitor's browser in the form of a cookie. Browsers can accept cookies. If present, it will be stored on the visitor's hard drive as a plain text record. Now, when a visitor reaches another page on the site
