<?php

include("database.php");

include("session_start.php");

include("session_check.php");

date_default_timezone_set('Asia/Calcutta');

$user_log = $_SESSION['username'];

$pass_log = $_SESSION['password'];

$login = mysql_query("SELECT * FROM login WHERE username='".$_SESSION['username']."' and password='".$_SESSION['password']."' ") or die (mysql_error());

echo "SELECT * FROM login WHERE username='".$_SESSION['username']."' and password='".$_SESSION['password']."' "; 

$num = mysql_num_rows($login);

$row1 = mysql_fetch_array($login) or die (mysql_error()); 



$uname_log = $row1['uname'];





// Logging class initialization

$log = new Logging();

 

// set path and name of log file (optional)

$log->lfile('/mylog.txt');

 

// write message to the log file

$ipaddress = $_SERVER['REMOTE_ADDR']."\r\n";

$date = date('d/F/Y h:i:s');

$webpage = $_SERVER['SCRIPT_NAME'];

$browser = $_SERVER['HTTP_USER_AGENT'];

$log->lwrite('----------------------------------------------------------------');

$log->lwrite("IP addr :".$ipaddress);

$log->lwrite("Date :".$date);

$log->lwrite("Username :".$user_log);

$log->lwrite("Password:".$pass_log);

$log->lwrite("Name :".$uname_log);

$log->lwrite('----------------------------------------------------------------');

 

// close log file

$log->lclose();



/**

 * Logging class:

 * - contains lfile, lwrite and lclose public methods

 * - lfile sets path and name of log file

 * - lwrite writes message to the log file (and implicitly opens log file)

 * - lclose closes log file

 * - first call of lwrite method will open log file implicitly

 * - message is written with the following format: hh:mm:ss (script name) message

 */

class Logging {

    // declare log file, newline character and file pointer as private properties

    private $log_file, $nl, $fp;

    // set log file (path and name)

    public function lfile($path) {

        $this->log_file = $path;

    }

    // write message to the log file

    public function lwrite($message) {

        // if file pointer doesn't exist, then open log file

        if (!$this->fp) {

            $this->lopen();

        }

        // define script name

        $script_name = pathinfo($_SERVER['PHP_SELF'], PATHINFO_FILENAME);

        // define current time and suppress E_WARNING if using the system TZ settings

        // (don't forget to set the INI setting date.timezone)

        $time = @date('H:i:s');

        // write current time, script name and message to the log file

        fwrite($this->fp, "$message" . $this->nl);

    }

    // close log file (it's always a good idea to close a file when you're done with it)

    public function lclose() {

        fclose($this->fp);

    }

    // open log file (private method)

    private function lopen() {

        // in case of Windows, set newline and default log file

        if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {

            $this->nl = "\r\n";

            $log_file_default = '/logfile.txt';

        }

        // set newline and default log file for Linux and other systems

        else {

            $this->nl = "\n";

            $log_file_default = '/logfile.txt';

        }

        // define log file from lfile method or use previously set default

        $lfile = $this->log_file ? $this->log_file : $log_file_default;

        // open log file for writing only and place file pointer at the end of the file

        // (if the file does not exist, try to create it)

        $this->fp = fopen($lfile, 'a') or exit("Can't open $lfile!");

    }

}



?>