Location: PHPKode > projects > Itshomi PHP Framework > itshomi/components/imiuser/DoLogout.php
<?
/*************************************************************
*                         Do User Logout                     *
*                 Copyright ALM Software Technologies             *
*                  Created by: Fernando Martinez             *
*                        15/12/05                            *
**************************************************************/

/** perform user logout */
class DoLogout extends ImiComponent
{
	private $db;
    
	function doTask()
	{
		if(!$_SESSION['LoggedIn'])
			return;
		$this->db = $this->navigator->getInstance('dbtable');
        $this->db->useTable('user');
		$_SESSION['LoggedIn']=false;
		$_REQUEST['feedback']="You have been successfully logged out";
		$_SESSION['uname']=null;
        $_SESSION['formdata'] = null;
        $_SESSION['email'] = null;
        $_SESSION['usertype'] = null;
		//$this->updateLoggedCount();
        $this->updateUserData($_SESSION['uid']);
        $_SESSION['uid']=null;
		$_SESSION['bid']=null;
		$_SESSION = array();

		if (isset($_COOKIE[session_name()])) {
		   setcookie(session_name(), '', time()-42000, '/');
		}
		session_destroy();

	}
	
	/** update count of users currently logged in */
	function updateLoggedCount()
	{
		$this->db->useTable('app');
		$appData = $this->db->getRows("id=1");
		if(count($appData)>0)
			$loggedCount = $appData[0][1];
		$names = array();
		$values = array();
		$names[0]="loggedcount";
		if(!isset($loggedCount))
		{
			$values[0]=0;
			$this->db->addRow($names,$values);
			return;
		}
		$loggedCount--;
		if($loggedCount<0)
		{
			$loggedCount = 0;
		}
		$values[0] = $loggedCount;
		$this->db->updateRows($names,$values,"id=1");
	}
    
    function updateUserData($uid)
    {
        $this->db->useTable("user");
        $names = array();
        $values = array();
        $names[0]="loggedin";
        $values[0] = "0";
        error_log("Logging out userid:".$uid);
        $this->db->updateRows($names,$values,"id=".$uid);
    }
}
Return current item: Itshomi PHP Framework