<?php

  /*

      logout.php

      This page Logs the user out of the system. [Commented]
  
      Changelog:
        2006-01-14 dave: Cleaned up code for v1.0 release

      ## PAGE CONTAINS HANDYANDY MYSQL MODS ##
      ## Copyright (C) 2005 Andy Deakin (handyandy.org.uk) ##

      ----
      TO DO

      Sort out working with no domains.
      ----

      Copyright (C) 2002  David Thorne (davethorne@gmail.com)

      This program is free software; you can redistribute it and/or
      modify it under the terms of the GNU General Public License
      as published by the Free Software Foundation version 2.

      This program is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      GNU General Public License for more details.

      You should have received a copy of the GNU General Public License
      along with this program; if not, write to the Free Software
      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

  */

  require_once 'system/db.php';
  require_once 'system/logs.php';

  // Start session and populate it with data
  session_start();

  $dirname = dirname($_SERVER['PHP_SELF']);
  $https = 'http'.($_SERVER['HTTPS'] ? 's' : '');
  $headertext = "Location: $https://".$_SERVER['HTTP_HOST'].$dirname.
    (strrpos($dirname,'/') == (strlen($dirname)-1)?'':'/').'index.php';

  if ($_SESSION['_id'] != '') {
    makelog($_SESSION['_id'],$_SESSION['_domain'],'LOGOUT',"$_SESSION[_name] has successfully logged out.");

    // Destroy any session that might exist effectively logging off
    session_destroy();
  }

  header($headertext);
?>
