Wednesday, August 01, 2007

Expreience PHP (CI Session)

CodeIgniter: http://www.codeigniter.com/

- CI Session:

The Session class permits you maintain a user's "state" and track their activity while they browse your site. The Session class stores session information for each user as serialized (and optionally encrypted) data in a cookie. It can also store the session data in a database table for added security, as this permits the session ID in the user's cookie to be matched against the stored session ID. By default only the cookie is saved. If you choose to use the database option you'll need to create the session table as indicated below.

Note: The Session class does not utilize native PHP sessions. It generates its own session data, offering more flexibility for developers.

If The session was encrypt that config in config file. We can use serialize, unserialize and urlencode, urldecode to unencrypt.

Example:
$c = unserialize(urldecode('a%3A8%3A%7Bs%3A10%3A%22session_id%22%3Bs%3A32%3A%22b4a94cbd5433e19108001ee784edc8fc%22%3Bs%3A10%3A%22ip_address%22%3Bs%3A9%3A%22127.0.0.1%22%3Bs%3A10%3A%22user_agent%22%3Bs%3A50%3A%22Mozilla%2F5.0+%28Windows%3B+U%3B+Windows+NT+5.1%3B+en-US%3B+rv%22%3Bs%3A13%3A%22last_activity%22%3Bi%3A1185940671%3Bs%3A10%3A%22last_visit%22%3Bi%3A0%3Bs%3A6%3A%22zip_code%22%3Bs%3A8%3A%22132-5648%22%3B%7Ds%3A9%3A%22member_id%22%3Bs%3A2%3A%2241%22%3Bs%3A11%3A%22member_g_id%22%3Bs%3A1%3A%222%22%3B%7D'));
//$c = unserialize(urldecode('%3A2%3A%2241%22%3Bs%3A11%3A'));
$c['user_id'] = 'admin';
unset($c['member_id']);
unset($c['member_g_id']);
echo 'C = ' . urlencode(serialize($c));