duanjin9035 2013-04-26 02:26
浏览 48
已采纳

需要帮助使PHP登录会话持续更长时间

I am working on a site for a small (read: <50 users) nonprofit organization that I work with and my PHP knowledge is fairly limited. Currently I have a login script that I found from a tutorial online. The problem I am running into is that each user is logged out after about an hour or so.

Security really isn't an issue with the content and ideally I would like for someone to stayed logged in for multiple days or weeks. However, any search on Google about sessions length nets me people looking to shorten the logout timer.

As far as code goes, once the login page compares username and password to the database and follows with:

session_register("myusername");
session_register("mypassword");
header("location:index.php")

And on each protected page it starts with:

session_start();
if(!session_is_registered(myusername)){
header("location:login.html:);
}
  • 写回答

3条回答 默认 最新

  • dsxjot8620 2013-04-26 02:29
    关注

    Edit your .htaccess and put something like:

    php_value session.gc_maxlifetime 2000
    

    2000 is in seconds. Set accordingly! This will tell the session garbage collector not to destroy the session for 2000 seconds. Also, session_register is deprecated.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题