PHP - session_module_name() 函式



定義和用法

Session 或 session 處理是一種使資料可在 Web 應用程式的各個頁面之間共享的方式。session_module_name() 用於設定或檢索當前 session 的儲存處理程式/模組。

語法

session_module_name([$module] );

引數

序號 引數 & 說明
1

path(可選)

這是一個字串值,表示要儲存 session 資料的路徑。

返回值

此函式返回一個字串值,表示當前 session 模組的名稱。

PHP 版本

此函式首次引入於 PHP 4 版本,並在所有後續版本中均有效。

示例 1

以下示例演示了 session_module_name() 函式的用法。

<html>   
   <head>
      <title>Setting up a PHP session</title>
   </head>   
   <body>
      <?php  	
         //Retrieving the module name
         $res = session_module_name();			 
         //Starting the session
         session_start();		
         print("Module Name: ".$res);	 		 
      ?>
   </body>   
</html> 

執行上面的 html 檔案,將顯示以下訊息:

Module Name: files

示例 2

您可以使用此函式設定當前 session 的模組名稱,如下所示:

<html>   
   <head>
      <title>Setting up a PHP session</title>
   </head>   
   <body>
      <?php  	
         //Setting the module name
         session_module_name("files");	
         $res = session_module_name();			 
		 
         //Starting the session
         session_start();		
         print("Module Name: ".$res);	 		 
      ?>
   </body>   
</html> 

這將產生以下輸出:

Module Name: files
php_function_reference.htm
廣告