<?php
//function to perform ReportLog(Report_Type,File,Details)
function ReportLog($Report_Type,$File)
{
  $dir=__DIR__."/LOG";//echo $dir;
  if(!is_dir($dir))mkdir($dir);if(!is_dir($dir."/".$Report_Type))mkdir($dir."/".$Report_Type); //die($Report_Type);
  $report_info=new stdClass();
  $report_info -> Type= $Report_Type;
  $report_info -> File= $File;
  if(isset($_SERVER['HTTP_USER_AGENT']))$report_info -> HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT'];
  if(isset($_SERVER['REQUEST_URI']))$report_info -> REQUEST_URI = $_SERVER['REQUEST_URI'];
  if(isset($_SERVER['HTTP_REFERER']))$report_info -> HTTP_REFERER = $_SERVER['HTTP_REFERER'];
  $ip="";
      if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
        $ip = $_SERVER['HTTP_CLIENT_IP'];
    } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    } else {
        $ip = $_SERVER['REMOTE_ADDR'];
    }
  $report_info -> ip= $ip;
  $myfile = fopen(__DIR__."/LOG/".$Report_Type."/".time()."-".rand(100,999).".log", "w") or die("Unable to open file!");
  $txt = json_encode($report_info);
  fwrite($myfile, $txt);
  fclose($myfile);

}
?>
