PHP - session_commit() Function



Definition and Usage

Sessions or session handling is a way to make the data available across various pages of a web application. The session_ commit() function saves all the session data and closes it. It is an alias of session_write_close().

Syntax

session_commit();

Parameters

This function doesnt accept any parameters.

Return Values

This function returns a boolean value which is TRUE in case of success and FALSE in case of failure.

PHP Version

This function was first introduced in PHP Version 4 and works in all the later versions.

Example 1

Following example demonstrates the usage of the session_commit() function.

   
   
      Setting up a PHP session
      
   
      ";
         print("Value: ".$_SESSION["A"]);
      ?>
      

One executing the above html file it will display the following message −

Value of the session array: Array ( [A] => Hello )
Value: Hello  

Example 2

Following is another example of this function, in here we have two pages from the same application in the same session −

session_page1.htm



   
      








Next'; ?>

This will produce the following output −

Session Start

On clicking on Next the following file is executed.

session_page2.htm

   
   
      Second Page
   
   
         
      

If you observe the contents of the session, since we have closed the session before adding the variable test, it is not added.

Array ( [city] => Hyderabad [phone] => 9848022338 [name] => krishna [age] => 30 )
php_function_reference.htm
Advertisements