### Session Security Tips
Despite there simplicity, there are still ways using sessions can go wrong. Here is a quick overview of some security techniques you can use to ensure you are using sessions safely.
#### Session Time-Outs
Timing-out sessions is a very important action if you are dealing with users logged in to your website or application. If a user logs in to your site in an Internet café and then leaves the computer and café without logging out, how do you stop the next user on that computer from still having access to the previous user’s session? Well you can use the following code:
~~~
<?php
session_start();
// set time-out period (in seconds)
$inactive = 600;
// check to see if $_SESSION["timeout"] is set
if (isset($_SESSION["timeout"])) {
// calculate the session's "time to live"
$sessionTTL = time() - $_SESSION["timeout"];
if ($sessionTTL > $inactive) {
session_destroy();
header("Location: /logout.php");
}
}
$_SESSION["timeout"] = time();
~~~
The code ensures that if there is no activity for more than 600 seconds (10 minutes) the request is redirected to the logout page which would successfully log out the user.
* * * * *
https://www.sitepoint.com/php-sessions/
- 数组
- 深拷贝
- 数组操作
- 交/并/合
- 差值
- 搜索
- 排序
- 货币
- 字符串
- 补全
- heredoc
- session
- 注销
- 限时自动注销
- 日期时间
- 日期时间
- 某月首尾
- 格式判断
- 年龄计算
- 时间函数
- strtotime
- 版本升级
- $HTTP_RAW_POST_DATA
- 正则函数等
- 版本比较
- php5.3 PHP5.4 PHP5.5 php5.6 新特性
- PHP注释
- URL地址
- 页面超时
- 类方法
- 静态方法
- 子类静态方法
- 普通方法和静态方法
- call_user_func 和 call_user_func_array
- 函数
- 动态函数
- 数组循环
- Math函数
- 取整
- 除数余数
- 运行模式
- CLI 模式
- 常用CLI命令
- 检测环境支持php_cli模式?
- 调试
- 调试工具
- FirePHP
- ChromePHP
- 内置服务器
- 500 错误处理
- 命令行
- 远程操作
- HTTP
- HTTP headers
- 用例
- 保留字
- 教程
- PHP实战教程-0基础快速入门
- 接口与抽象类
- 抽象类与接口的区别
- 魔术方法
- 私有属性方法
- 构造/析构方法
- PHP Error 和 Logging 函数
- 类
- const