dongshan2004 2012-10-02 03:09
浏览 44

使用php和mysql,在用户注销时插入时间戳

Using PHP and MySQL

When a user logs in I am able to insert their log-in time-stamp into MySQL while using sessions and with the use of a function. The function would update the database and works wonderfully.

Now, is it possible to get a time-stamp and have it recorded into MySQL the same way when the user clicks on "log-out" and where the log-out will run session_destroy()?

All I am looking for is a time stamp of when the user clicks on log-out, just so I know they have been log-out. I not worried if they just closed the browser and walked away.

I have tried doing something like session_destroy(something); and using this as function. All I got was run-time errors. Is this something that is even possible to do?

  • 写回答

3条回答 默认 最新

  • dousidan1279 2012-10-02 03:11
    关注

    You should have no problem recording a logout time when a user clicks logout (of course this won't work if the browser is closed). Just get the UserID and update that user in the database before calling session_destroy().

    For example:

    Logout.php

    $query = "update user set logoutDate=CURRENT_TIMESTAMP where user={$_SESSION['userID']}";
    mysql_query($query);
    
    session_destroy();
    
    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法