Restrict frequent Website access

Source: Internet
Author: User
Execution of the stored procedure procAccessIP (@ ip, @ seconds, @ maxTimes) returns 0 or 1. If procAccessIP (127.0.0.1, 5, 5) is set, if the access to this stored procedure exceeds 5 times within 5 seconds, 1 is returned, otherwise 0 is returned without CREATETABLE [dbo]. [Zz_AccessIP] ([IP] [nvarchar] (50) NOTNULL, [FirstDateTim

Execute the Stored Procedure procAccessIP (@ ip, @ seconds, @ maxTimes) and return 0 or 1. If procAccessIP ('123' is set. 0.0.1 ', 5, 5) indicates that if the stored procedure is accessed more than 5 times within 5 seconds, 1 is returned; otherwise, 0 is returned and no create table [dbo] is returned. [Zz_AccessIP] ([IP] [nvarchar] (50) not null, [FirstDateTim

Execution of the stored procedure procAccessIP (@ ip, @ seconds, @ maxTimes) returns 0 or 1
If procAccessIP ('127. 0.0.1 ', 5, 5) is set, 1 is returned if the stored procedure is accessed more than 5 times in 5 seconds. Otherwise, 0 is returned.


<无>
CREATE TABLE [dbo].[Zz_AccessIP]([IP] [nvarchar](50) NOT NULL,[FirstDateTime] [datetime] NOT NULL,[LastDateTime] [datetime] NOT NULL,[Times] [int] NOT NULL, CONSTRAINT [PK_Zz_AccessIP] PRIMARY KEY CLUSTERED ([IP] ASC)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]) ON [PRIMARY]GOALTER TABLE [dbo].[Zz_AccessIP] ADD  CONSTRAINT [DF_Zz_AccessIP_FirstDateTime]  DEFAULT (getdate()) FOR [FirstDateTime]GOALTER TABLE [dbo].[Zz_AccessIP] ADD  CONSTRAINT [DF_Zz_AccessIP_LastDateTime]  DEFAULT (getdate()) FOR [LastDateTime]GOALTER TABLE [dbo].[Zz_AccessIP] ADD  CONSTRAINT [DF_Zz_AccessIP_Times]  DEFAULT ((0)) FOR [Times]GO
-- If the number of accesses exceeds 5 by default within 5 seconds, 1 is returned; otherwise, 0 CREATE proc [dbo] is returned. [procAccessIP] (@ ip nvarchar (50), @ seconds int = 5, -- how long is the default value of @ maxTimes int = 5 in five seconds? -- limit the maximum number of visits, 5 times by default) asbegin -- delete a delete from [Zz_AccessIP] where DateDiff (second, LastDateTime, GetDate ()> @ seconds and IP = @ ip; -- delete a delete from [Zz_AccessIP] where DateDiff (second, FirstDateTime, GetDate ()> @ seconds and Times <@ maxTimes and IP = @ ip; -- declare @ existsIp int; select @ existsIp = count (IP) from [Zz_AccessIP] where IP = @ IP; if @ existsIp = 0 insert into [Zz_AccessIP] (IP) values (@ ip); elseupdate [Zz_AccessIP] set Times = Times + 1, LastDateTime = GETDATE () where IP = @ ip; -- obtains whether the number of visits to an IP address exceeds 5 declare @ count int in 5 seconds; select @ count = COUNT (IP) from [Zz_AccessIP] where IP = @ ip and DateDiff (second, LastDateTime, GetDate () <@ seconds and Times> @ maxTimes; return @ count; endGO
DECLARE@return_value intEXEC@return_value = [dbo].[procAccessIP]@ip = N'127.0.0.1',@seconds = 5,@maxTimes = 5SELECT'Return Value' = @return_valueGO

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.