• PHP Video Tutorials

PHP - session_save_path() 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_save_path() is used to set or retrieve the path where the current session data is saved.

Syntax

session_save_path([$path ] );

Parameters

Sr.No Parameter & Description
1

path (Optional)

This is a string value representing the path where the session data is to be stored.

Return Values

This function returns a string value representing the path of the directory in which the current session data is stored.

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

<html>   
   <head>
      <title>Setting up a PHP session</title>
   </head>   
   <body>
      <?php  	
         ini_set('session.save_path', '/data');

         //Retrieving the session save path
         $res = session_save_path();	
		 
         //Starting the session
         session_start();		
         print("path: ".$res);	 
      ?>
   </body>   
</html> 

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

path: /data

Example 2

You can also set the session save path using this function as shown below −

<html>   
   <head>
      <title>Setting up a PHP session</title>
   </head>   
   <body>
      <?php  	
         //Setting the session path
         session_save_path('/data');
         
         //Retrieving the session save path
         $res = session_save_path();			 
         
         //Starting the session
         session_start();		
         print("path: ".$res);	 		 
      ?>
   </body>   
</html> 

This will produce the following output −

path: /data
php_function_reference.htm
Advertisements