The younger brother is confused.

Source: Internet
Author: User
Ask the bosses for some confusing things. The younger brother's system (a cms) has a search page. the following code prevents users from frequently searching for $ lockfile = '. /time. lock. inc '; // time. lock. inc content: 1337659312 $ lasttime = file_ge ask your boss, younger brother, something confusing.
The following code shows a search page in the younger brother's system (a cms) to prevent frequent searches.
$ Lockfile = './time. lock. inc'; // time. lock. inc: 1337659312
$ Lasttime = file_get_contents ($ lockfile );

If (! Empty ($ lasttime) & ($ lasttime + $ pai_search_time)> time ())
{
ShowMsg ('Do not operate frequently ','-1 ');
Exit ();
}
After each search, the current time is updated to time. lock. inc.

This code prevents all users from performing more than two operations at the same time within the specified $ pai_search_time, but it is definitely inappropriate.
The reasons are as follows (I do not know if it is appropriate). Please help analyze the reasons:
Suppose $ pai_search_time = 1 at the same time, there are 20 people in the concurrent search ideal situation, and it will take 20 seconds (the server and network speed consumption time are negligible ).

Because of this, I want to improve the storage of two messages in time. lock. inc. one IP address and one timestamp.
$ Dataiplist0 => array ('14. 453.22.55 '=> 1337659312 ,...);
?>
Then, each time an IP address is obtained, the specified IP address can be searched only once within one second for the same IP address during each search. This allows concurrent search, however, there is a problem here. if users in an intranet segment use the same Internet IP address to access the Internet, the entire Intranet may be treated as a user, I don't know how to deal with these problems.

Finally, I am weak. can this effectively control malicious harassment by users? If not, can you give me some suggestions...




------ Solution --------------------
Save array to this file,
The session id is the key and the value is the timestamp of the last search.
------ Solution --------------------
This is because there should not be many people to search for, except for some (action) forums.
You can use memcache to save data.

Use a combination of ip + User name + search time to determine


------ Solution --------------------
Your initial lock is for all users, so it is correct to use the filelock.

Later, you want to lock a single user, so you can use session.
------ Solution --------------------
Session Control is enough. if you want to prevent hackers, the session has no effect on them. if you don't submit cookies, you can.
------ Solution --------------------
Create a new table and add the user to search. Determine whether there are records or the time is within a certain range. I won't check it again.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.