我阅读了有关将 codeigniter 会话存储到数据库中的信息。当我听说 codeigniter 会话被保存到 cookie 中并且由于我的网站使用会话进行身份验证和设置权限时,我非常担心,所以我设计了代码来检查 cookie 的工作原理:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class sess extends CI_Controller
{
public function loadsession()
{
$this->session->set_userdata('username','administrator');
$this->session->set_userdata('password','abcdef123456');
}
}
/* End of file sess.php */
/* Location: ./application/controllers/sess.php */
这是结果 cookie (ci_session):
a%3A7%3A%7Bs%3A10%3A%22session_id%22%3Bs%3A32%3A%2298867177e69b4d33059c7517782bdfc9%22%3Bs%3A10%3A%22ip_address%22%3Bs%3A13%3A%22192.168.1.100%22%3Bs%3A10%3A%22user_agent%22%3Bs%3A120%3A%22Mozilla%2F5.0+%28iPhone%3B+U%3B+CPU+iPhone+OS+3_0+like+Mac+OS+X%3B+en-us%29+AppleWebKit%2F528.18+%28KHTML%2C+like+Gecko%29+Version%2F4.0+Mobil%22%3Bs%3A13%3A%22last_activity%22%3Bi%3A1373188924%3Bs%3A9%3A%22user_data%22%3Bs%3A0%3A%22%22%3Bs%3A8%3A%22username%22%3Bs%3A13%3A%22administrator%22%3Bs%3A8%3A%22password%22%3Bs%3A12%3A%22abcdef123456%22%3B%7D3ef00c243e040389e98ab204933d4c8c
包含原始数据:
用户名%22%3Bs%3A13%3A%22管理员%22%3Bs%3A8%3A%22password%22%3Bs%3A12%3A%22 abcdef123456 %22%3B%7D3ef00c243e040389e98ab204933d4c8c
我不知道如何在 Firefox 中更改 cookie,但如果我这样做,它会欺骗服务器吗?如何防止?在数据库中保存会话是否可以保护我免受此类欺诈?