2
votes

I want to delete session files automatically in PHP.

I came to know that I have to change the following configurations in PHP.ini

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

But I am not sure that what value to change in these properties.

2
If you keep the PHP save session path to default, PHP should automatically clear them up. If you change the path, you have to clean it yourself. - Clarkey
What do you mean automatically? After a certain time period or when the user logs out? - Chris
This question has useful information about the automatic session file cleanup. - T30

2 Answers

1
votes

Probably this example will help you

 <?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(); 
 ?> 
-1
votes

Using session_destroy(); function, created session files deleted from automatically.