【问题标题】:Delete Session files automatically in PHP在 PHP 中自动删除 Session 文件
【发布时间】:2012-04-27 18:30:25
【问题描述】:

我想在 PHP 中自动删除会话文件。

我知道我必须在PHP.ini中更改以下配置

  • session.gc_probability
  • session.gc_divisor
  • session.gc_maxlifetime

但我不确定这些属性要更改什么值。

【问题讨论】:

  • 如果您将 PHP 保存会话路径保持为默认值,PHP 应该会自动清除它们。如果你改变路径,你必须自己清理它。
  • 自动是什么意思?一段时间后或用户退出时?
  • This question 有关于自动会话文件清理的有用信息。

标签: php file session delete-file


【解决方案1】:

这个例子可能会对你有所帮助

 <?php 
 // you have to open the session to be able to modify or remove it 
 session_start(); 

 // to change a variable, just overwrite it 
 $_SESSION['variable_name']='variable_value'; 

 //you can remove a single variable in the session 
 unset($_SESSION['variable_name']); 

 // or this would remove all the variables in the session, but not the session itself 
 session_unset(); 

 // this would destroy the session variables 
 session_destroy(); 
 ?> 

【讨论】:

  • 通常为了删除会话文件,有一个 CRON 可以删除它们。您是否拥有对服务器的完全访问权限?
【解决方案2】:

使用session_destroy();函数,创建的会话文件自动删除。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-08
    • 1970-01-01
    • 2012-03-06
    • 1970-01-01
    • 1970-01-01
    • 2011-04-07
    相关资源
    最近更新 更多