PHP - session_reset() 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_reset() function re-initializes the variables of a session with original values.

Syntax

session_reset();

Parameters

This function does not accept any parameters.

Return Values

This function returns a boolean value which is TRUE if the session started successfully and FALSE if not.

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_reset() function.

   
   
      Setting up a PHP session
      
   
      ";		 
      ?>
      
 

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

Initial value: Hello

Then you need to execute the following file.

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

This generates the following output.

New value: Welcome
Value after the reset operation: 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 status

On clicking on Next the following file is executed.

session_page2.htm

   
   
      Second Page
   
   
      ";
         print($_SESSION['age']);
      ?>   
      

This will produce the following output −

Radha
22
Values after the reset operation:
krishna
30 
php_function_reference.htm
Advertisements