session_start(); ini_set("session.gc_maxlifetime", "10"); //in second if(isset($_SESSION['active'])){ }else{ session_unset(); session_destroy(); ?> <SCRIPT LANGUAGE="Javascript"> alert ('Your sesion has expired.\nPlease login again!'); document.location = "login.php" </SCRIPT> <?php exit; } ?> PHP: i want to destroy the session if the user do not have respone in a period of the time. i search from internet is the above code. but when i trying it doesn't work? do i miss something or...???
Does it shows the error message (javascript alert), or not? If not, the if statement seems to be not working. Else, try using session_unregister('global-session-variable-name'); Also you could try using session_destroy() only. edit: this helps with me: - this code removes unnecessary cookies. if (isset($_COOKIE[session_name()])) { setcookie(session_name(), '', time()-42000, '/'); } PHP: