• PHP Video Tutorials

PHP - session_gc() 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_gc() function is used to set user-level session storage functions using which you can store and retrieve the data associated with the current session.

Syntax

session_gc();

Parameters

This function does not accept any parameters.

Return Values

This function returns an integer value representing the number of data items deleted in the current session in case of success and, a boolean value which is 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_gc() function.

<html>   
   <head>
      <title>Second Page</title>
   </head>
   <body>
      <?php
         $expire = session_cache_expire(10);
         //Starting the session
         session_start();   		 
		 
         //Garbage collection
         $res = session_gc();         		 
         print("Deleted Values: ".$res);
      ?>   
   </body>   
</html>

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

Deleted Values:2 
php_function_reference.htm
Advertisements