-3

I have a server with PHP and MySQL etc.

I want to destroy all the sessions connected to this server (cookies also)

The normal code to sign out

<?php
setcookie("username", "", time()-31536000);
session_start();
session_destroy();   
session_unset();
header("Location: index.html");
?>
Dharman
  • 30,962
  • 25
  • 85
  • 135
  • 1
    What are you trying to accomplish? Sessions can be stored almost anywhere (different directories, databases, custom storage...) and there's no API to directly access sessions from other users, let alone apps. Also, random cookies like `username` are an entirely different business. – Álvaro González Oct 14 '20 at 13:49
  • Does this answer your question? [How to kill a/all php sessions?](https://stackoverflow.com/questions/5193744/how-to-kill-a-all-php-sessions) – SeeoX Oct 14 '20 at 14:18

1 Answers1

0

You can find where does session are stored with https://www.php.net/manual/en/function.session-save-path.php session_save_path() and then delete them with something like

$files = glob(session_save_path().'*'); 
foreach($files as $f){ 
  if(is_file($f)) {
    unlink($f); 
  }
}
magrigry
  • 405
  • 2
  • 8
  • this code reset the session state (deleting everything in session setting like my cart, my fav setting etc...) but doesn't log out all the computers and mobiles session in my server – Yosef Atef Farouck Oct 15 '20 at 08:53
  • @YosefAtefFarouck That's because sessions can be stored almost anywhere (different directories, databases, custom storage...) and there's no API to directly access sessions from other users, let alone apps. – Álvaro González Oct 15 '20 at 10:24
  • It does log out users. If you are using session for loging in users then deleting the session will log them out from your app. – magrigry Oct 15 '20 at 10:33
  • exactly , that's what i want – Yosef Atef Farouck Dec 10 '20 at 15:01