简体   繁体   中英

trying to detect id the user is between the first 8 hours and next 8 hours or last 8 hours

I am trying to create a log entry where i want to check if the user is visiting first time or 2nd or 3rd time or multiple times

In this case i am considering the time to be split into 8,16,26 so if the same user is coming back and forth in first 8 hours, it should only make one entry in db and if the user is again coming back in the next 8 hours it should make another entry and once the entry is made within the 8 hour slot, he can come and go multiple times but only 1 entry will be made

so in that case i am trying to use the code starting here

 var sessionRotated = dateConvert('local2Utc', now()).hour();
<cfif sessionRotated  LTE 8> <!--- first entry --->
    <cfset entry_1 = true>
</cfif>

<cfif sessionRotated  LTE 16 AND sessionRotated  gte 8> <!--- first entry --->
    <cfset entry_2 = true>
</cfif>

<cfif sessionRotated  LTE 16 and sessionRotated  GTE 24> <!--- first entry --->
    <cfset entry_3 = true>
</cfif>

but i am missing a logic here how can i use it along with the IPAddress

any idea

A couple of things here.

  1. You're only looking at the hour of the current time. This has no relation to the previous time a user visited your site. You need dateDiff() in here somewhere
  2. You'll have to store the last visit datetime in your database.
  3. Optionally, you can update a cookie every time you get a new hit from this user and have that for your dateDiff()

Other points: Cookies can be cleared. This isn't foolproof. IP Addresses can change. VPN's, new connection at a different Starbucks, different computer, etc. If you have a login system, that's a much better way to track a specific user. Anytime you're looking at just the HOUR, you aren't considering first hit at 11am, next hit at 2pm.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM