请教各位老大,小弟有些迷惑的东西。
小弟的系统(一个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就是了.
------解决方案--------------------
新建一表,把搜索的用户放进去。判断是否有记录或者时间在一定范围内。就不让再查了

PHPisusedforsendingemailsduetoitsintegrationwithservermailservicesandexternalSMTPproviders,automatingnotificationsandmarketingcampaigns.1)SetupyourPHPenvironmentwithawebserverandPHP,ensuringthemailfunctionisenabled.2)UseabasicscriptwithPHP'smailfunct

The best way to send emails is to use the PHPMailer library. 1) Using the mail() function is simple but unreliable, which may cause emails to enter spam or cannot be delivered. 2) PHPMailer provides better control and reliability, and supports HTML mail, attachments and SMTP authentication. 3) Make sure SMTP settings are configured correctly and encryption (such as STARTTLS or SSL/TLS) is used to enhance security. 4) For large amounts of emails, consider using a mail queue system to optimize performance.

CustomheadersandadvancedfeaturesinPHPemailenhancefunctionalityandreliability.1)Customheadersaddmetadatafortrackingandcategorization.2)HTMLemailsallowformattingandinteractivity.3)AttachmentscanbesentusinglibrarieslikePHPMailer.4)SMTPauthenticationimpr

Sending mail using PHP and SMTP can be achieved through the PHPMailer library. 1) Install and configure PHPMailer, 2) Set SMTP server details, 3) Define the email content, 4) Send emails and handle errors. Use this method to ensure the reliability and security of emails.

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.

ThebestpracticesforsendingemailssecurelyinPHPinclude:1)UsingsecureconfigurationswithSMTPandSTARTTLSencryption,2)Validatingandsanitizinginputstopreventinjectionattacks,3)EncryptingsensitivedatawithinemailsusingOpenSSL,4)Properlyhandlingemailheaderstoa


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

Dreamweaver Mac version
Visual web development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Chinese version
Chinese version, very easy to use

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
