SQL |
-- add_session (30)
declare @id int
declare @projectid int = 3
declare @ip varchar(18) = '3.235.60.197'
declare @user_agent varchar(200) = 'CCBot/2.0 (https://commoncrawl.org/faq/)'
declare @country varchar(5) = 'USA'
declare @path varchar(200) = 'C:\WEB\ciaoseminars\cs2\index.cfm'
declare @blacklistid int = (select max(id) from blacklist where IP = @ip)
declare @logid int = (
select max(id) from sessions where ip = @ip and datediff(ss,date,dateadd(hh,-5,getdate())) <= 1800
-- removed user agent as same IP is logging mutliple user_agent --and user_agent = @user_agent
)
IF isNull(@logid,0) > 0 -- if the IP and browser exist within the last 120 seconds, re-use the sessionid
select @logid as logid, isNUll(@blacklistid,0) as blacklistid
ELSE
insert into sessions
(projectid,ip,country,user_agent,path)
values(3,@ip,@country,@user_agent,@path)
set @id = SCOPE_IDENTITY()
select @id as logid, isNull(@blacklistid,0) as blacklistid, @country as country |