### 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