Archive

Posts Tagged ‘php session mechanism’

php session mechanism:files

October 14th, 2010 No comments

Here I'm going to elaborates php session mechanism:files(files mechanism is also the most frequently used one).

In php.ini,session.save_handler = files instruct php using files mechanism in processing session.The files mechanism creates files in directory set by session.save_path in php.ini,and the filename is the cookie value on the client's side(cookie name is set by session.name in php.ini,PHPSESSID by defaults),for example,70mild37sara2jpa2rk3h8bjg1.To get the cookie value on the client's side,you go the follow steps in firefox(Or other browsers):Tools-Page Info-Security-View Cookies.Find the cookie name labeled PHPSESSID,click on it,and get the value of it.

On the server side,after the session's filename is ready,then time for the content of the session.You set the session content in PHP by using the $_SESSION global variable,for example,$_SESSION['email']='[email protected]',$_SESSION['firstname']='ff.Besides,you can use session_id([string $id]) to assign session id manually before session_start() turns up in your code.On the issue of session_id,refer to the url:http://www.php.net/manual/en/function.session-id.php

Then comes the most important matter:the mechanism session accomplish the task to identify unique user.Here are my comprehension on it.

Firstly,after end user opens a browser,which is also called UA(User Agent in computer term) ,a session is created.Then,the server side save the session to a file whose file descriptor specified by the client.Lastly,in order to determine whether the user is the one that talks to him,the server compares the file descriptor to end user's cookie value.

In general,different UA creates different session id.That's why you have to re-login your account after you switch browser from Firefox to IE.