PHP Training · Php5

All About Session in PHP

A session is basically a temporary set of variables used to transfer information from one page to another. More broadly we can say that it gives options to create once and used inside whole project. Through session we can manage general information inside a Web application. The best example of Session usage is in login/logout inside a web Application. That’s why we can say that Session is known as the Heart of Web Application. This information is stored temporarily for your PHP programs to refer back to whenever needed. Every session is assigned a unique session ID, which keeps all the current information together.

By default it is stored physically inside “tmp” directory in our Web server. Like session.save_path = “d:/wamp/tmp”.  OR session.save_path = “c:/wamp/tmp”, depend on your installation drive. The default directory can be change via  session.save_path setting inside php.ini. The directory which we will replace should be physically available inside our Web Hosting account.

The longivity of a session depend on either shut down of the specific browser where it is currently being used OR It’s longevity defined inside php.in setting like session.gc_maxlifetime = 1440.  (1440 seconds or 24 minutes).

Some basic Session related functions in PHP

session_start() — Start Session.

$_SESSION[‘username’] = $_POST[‘user_name’] OR

$_SESSION[‘username’] = $_GET[‘user_name’] OR

$_SESSION[‘username’] = ‘Constant_name’;

echo  $_SESSION[‘username’]; //Echo Session variable

session_destroy() — Destroys all data registered to a session

session_unset(); — Free all session variables

unset($_SESSION[‘name’]); — To remove a specific variable from the session.

We can extend the longevity of a session by using cookie also.

This setting is determined in your php.ini file. If you would like to force the user to pass variables through cookies (instead of allowing a backup plan), you would set the following line in your file:

session.use_only_cookies = 1

If you guys have more information about Session in PHP, plz share the information with us at

info@briansoftglobalservices.com, Web : http://www.briansoftglobalservices.com/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s