Thursday, August 25, 2011

PHP Session

HTTP
As we know that web built over HTTP (Hypertext Transfer Protocol), Protocol.HTTP is a stateless protocol.Each HTTP request is user session context independent, and the server is, on the HTTP protocol level, unaware of any relationship between consecutive requests.
In most web applications some user information or data need to be store at client side or at server.
In the PHP world, as in most web-oriented platforms, two main standard methods exist for storing short-term user specific data: Cookies and Sessions.
HTTP Cookies
 Cookies are set by the server, and are stored by the browser on the client machine. Browsers will re-send a Cookie to the same domain from which it originated, until it expires.Cookies are convenient and scalable (no storage is required on the server side), but are also limited due to a number of reasons.
  1. Cookies are limited in size and varies browser to browser.
  2. Cookies are sent repeatedly, on each request to the server.
  3. Cookies store string - to store more complex data you need serialization and de-serialization.
  4.  Cookie data is stored on the client side.
 These limitations make it almost impossible to rely on Cookies. To solve your problems PHP offers the Sessions concept.
PHP Sessions
When a PHP user session is started, the user is assigned a random, unique Session ID that is sent by the server to the browser. This session ID is then used as the key to a storage area on the server, which is unique for this session.
The Session ID is passed back and forth from the client to the server using either Cookies (as is more common in recent years) or by appending the Session ID to the URL’s query string. The only information sent between the client and the server is the ID – usually a random, short string of characters.



On the server side, session information can be stored in many ways.
  1. Files Storage ( default )
  2. In-Memory and other local storage
  3. Relational Database Storage
  4. Distributed Cache Storage (memcached)

4 comments:

nisha said...

gives good knowledge,please write something about the total internal process of loading a web page

abhishek saxena said...

Simply awsome dude...

Livingonedge said...

Usefull Info...

Well begun is half done.
You Rock Buddy..
Kindly post more information on language that has created wonders for few and made them Youngest Billionaires !!

Sonia said...

Good knowledge sharing!!! Please throw some light on multi dimentional arrays