-1

我有一个允许用户登录的网站。问题是我如何检查他们是否logged in. 尝试过这种方法 - 当用户登录时更新(用户表)行Logged进入'1'并且当他们注销更新logged行回到0时。这是通过获取用户名来完成的session

 $username=$_SESSION['username'];

但是,此方法不起作用,因为它仅适用于一个用户。我在某处读到timestamps是一种很好的实现方法,但我不知道该怎么做。

有什么帮助吗?谢谢!

4

1 回答 1

3

If you fill your $_SESSION['username'] with the username after successful login, this is your check if this variable is not empty.

A php session is determinted trough the PHPSESSID as query param or in a cookie (if enabled) so a session should be unique per browser and client and last until the browser is closed.

For time limited session you can save the logintime as a timestamp in session variable (ex. $_SESSION['logintime']) and automatically logout the user, if the timestamp is too much in the past.

于 2013-04-27T14:37:40.190 回答