PHP - session_gc() 函式



定義和用法

Session 或 session 處理是一種使資料在 Web 應用程式的各個頁面之間可用的一種方式。session_gc() 函式用於設定使用者級 session 儲存函式,您可以使用這些函式儲存和檢索與當前 session 關聯的資料。

語法

session_gc();

引數

此函式不接受任何引數。

返回值

如果成功,此函式返回一個整數值,表示當前 session 中刪除的資料項數;如果失敗,則返回布林值 FALSE。

PHP 版本

此函式最早在 PHP 版本 4 中引入,並在所有後續版本中均可使用。

示例 1

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

<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>

執行上述 html 檔案後,它將顯示以下訊息。

Deleted Values:2 
php_function_reference.htm
廣告