如何识别第一次用户登录时间

时间:2021-12-01 07:17:28

How to identify the first time user login and that time display some alert message in javascript can any body help me please ? guys

如何识别第一次用户登录和那个时间在javascript中显示一些警报消息可以帮助我吗?人

3 个解决方案

#1


Have a column in the user table LAST_LOGIN DateTime. Every time the user logs in update that record.

在用户表LAST_LOGIN DateTime中有一列。每次用户登录更新该记录。

By default make the column NULL. If LAST_LOGIN === null then it's the first time the user has logged in.

默认情况下,将列设为NULL。如果LAST_LOGIN === null,那么这是用户第一次登录。

#2


You can always use cookies:

您始终可以使用Cookie:

if (document.cookie != 'visited'){
  alert('Hey there, new user!');
  document.cookie = 'visited';
}

However, if the user clears history or cookies in between, this will be reset.

但是,如果用户清除其间的历史记录或cookie,则会重置该值。

A better way would be to have your server track which users have visited before.

更好的方法是让您的服务器跟踪之前访问过的用户。

#3


Make a first_login column in your DB. Check if it is empty when a user tries to login, if it is, populate the field with the current date & time, else do nothing.

在数据库中创建first_login列。当用户尝试登录时检查它是否为空,如果是,则使用当前日期和时间填充该字段,否则不执行任何操作。

   <?php
       // Assuming you know the user is logged in & validated.
       if($flogin === ""){
          // Query: "UPDATE SET first_login = NOW() WHERE user_id = '$logged_in_user_id'"
       }else {
         // Get first_login and display to the user
       }
   ?>

Not really sure if you know what you're doing since you're asking how to display something to the user, so, for more info please clarify more.

不确定你是否知道自己正在做什么,因为你问的是如何向用户展示一些东西,所以,更多信息请详细说明。

#1


Have a column in the user table LAST_LOGIN DateTime. Every time the user logs in update that record.

在用户表LAST_LOGIN DateTime中有一列。每次用户登录更新该记录。

By default make the column NULL. If LAST_LOGIN === null then it's the first time the user has logged in.

默认情况下,将列设为NULL。如果LAST_LOGIN === null,那么这是用户第一次登录。

#2


You can always use cookies:

您始终可以使用Cookie:

if (document.cookie != 'visited'){
  alert('Hey there, new user!');
  document.cookie = 'visited';
}

However, if the user clears history or cookies in between, this will be reset.

但是,如果用户清除其间的历史记录或cookie,则会重置该值。

A better way would be to have your server track which users have visited before.

更好的方法是让您的服务器跟踪之前访问过的用户。

#3


Make a first_login column in your DB. Check if it is empty when a user tries to login, if it is, populate the field with the current date & time, else do nothing.

在数据库中创建first_login列。当用户尝试登录时检查它是否为空,如果是,则使用当前日期和时间填充该字段,否则不执行任何操作。

   <?php
       // Assuming you know the user is logged in & validated.
       if($flogin === ""){
          // Query: "UPDATE SET first_login = NOW() WHERE user_id = '$logged_in_user_id'"
       }else {
         // Get first_login and display to the user
       }
   ?>

Not really sure if you know what you're doing since you're asking how to display something to the user, so, for more info please clarify more.

不确定你是否知道自己正在做什么,因为你问的是如何向用户展示一些东西,所以,更多信息请详细说明。