douzi2333 2012-04-01 20:41
浏览 23
已采纳

如何检索登录cookie(PHP)

Hi I have a textbox that takes a username input. When the user submits the form, a cookie is created that stores the time of the cookie. On the next page, I need to display the time they were last logged in. How can I do this using the following cookie code?

SETCOOKIE($_POST['name'], time(), time() + 60*60*24*30);
  • 写回答

1条回答 默认 最新

  • doucan8246326 2012-04-01 20:44
    关注

    You need to pass the users name everytime or save it in the server which is probably not the best solution here.. Why dont you have a static cookie name and do something like this when he logs in:

    SETCOOKIE('LASTLOGGEDINTIME', time(), time() + 60*60*24*30);
    

    $_COOKIE['LASTLOGGEDINTIME'] should retrieve the value.. do the necessary null/empty checks

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)