What is PHP Sessions?
What is PHP Sessions?
Session concept is very useful for Web based applications to pass and share information from one web page (request) to another Web page (request). Session support in PHP consists of a way to preserve certain data across subsequent accesses. This enables you to build more customized applications and increase the appeal of your web site. A visitor accessing your web site is assigned a unique id, the so-called session id. This is either stored in a cookie on the user side or is propagated in the URL. A PHP session solves this problem by allowing you to store user information on the server for later use (i.e. username, shopping cart items, etc). However, this session information is temporary and is usually deleted very quickly after the user has left the website that uses sessions.
When the server receives a request from a browser on a new client host (request without a session ID), the server should not only create a new session ID, it should also create a new session object associated with the new session ID. This session object should become the storage place for different requests of the same session to store and share information. Sessions work by creating a unique identification (UID) number for each visitor and storing variables based on this ID. This helps to prevent two users’ data from getting confused with one another when visiting the same webpage.
How To Enable Session Support for PHP?
The session support can be turned on automatically at the site level, or manually in each PHP page script: Turning on session support automatically at the site level we have to modify some setting in php.ini file. you can get php.ini file in folder you install PHP. To you sessions you have to set or reset following parameter in your php.ini file
Define path to save sessions
session.save_path = “C:\php\sessiondata\”
Whether to use cookies.
session.use_cookies = 1
To Initialize session on request startup.
Set session.auto_start = 1
Name of the session (used as cookie name).
session.name = PHPSESSID
Define Lifetime in seconds of cookie or, if 0, until browser is restarted.
session.cookie_lifetime = 0;
The path for which the cookie is valid.
session.cookie_path = /
The domain for which the cookie is valid.
session.cookie_domain =
Handler used to serialize data. php is the standard serializer of PHP.
session.serialize_handler = php
There are some more setting which may be used to modify your Sessions. For more Details refer php.ini
support manually in each page script:
Call session_start() funtion.

Add A Comment