What is the use of session_id() in PHP ?

Overview of session_id in PHP

The session_id() is one of the in built functions in PHP.  Almost in all Framework’s and CMS’s it has been utilized to find the current session.  In this tutorial we will see how to utilize this session_id() in small applications apart from Framework and CMS.  Generally the session_id() will be used to track existence of same user across all the pages of PHP application. A Realtime example would be “tracking whether same user is navigating from one page to another”.  Lets see how this session_id() will be generated in a web application.

The below code shows the generation of session_id();

The above code snippet shows how to set the session_id() in PHP. This session_id() will be generated whenever the page is calling session_start() function.

Below steps shows you how to check the current session in multiple pages.

Step 1: Have one session library function in your application, say for eg:- session.php

Step 2: Create one page in your application, eg:- error.php

Step 3: Create one page in your application, eg:- index1.php

Step 4: Create one page in your application, eg:- index2.php