-1) $store_string = $h; } //If no increase is not set if ( ! $_GET['ni'] ) { //Check if previously visited if (isset($_COOKIE['trackt'])) { $ingredients = explode(";",$store_string); $user_hash = $ingredients[0]; $count = $ingredients[1] + 1; $store_string = $user_hash.";".$count; } else { //Else create a cookie hash $user_hash = md5($_SERVER['REMOTE_ADDR'].$_SERVER['HTTP_USER_AGENT'].time()); setCookie("trackt",$user_hash,time()+60*60*24*30); $store_string = $user_hash.";1"; $cnt[] = $store_string."\n"; } } //Create log file foreach ($cnt as $h) { if (strpos($h,$user_hash) > -1) $log .= $store_string."\n"; //Add to hit log else $log .= $h; } //Store log file $fp = fopen($cntfile, "w"); fwrite($fp, $log); //If output requested if ( isset($_GET['output']) ) { //Grab file for output if(file_exists($cntfile) == TRUE) $cnt = file($cntfile); else $cnt = array(); //Total it up $total = 0; foreach ($cnt as $h) { $ingredients = explode(";",$h); $total += $ingredients[1]; } //Outputs if ($_GET['output'] == "xml") { // Output for XML header('Content-Type: application/xml'); echo ''; ?> array( "hits" => $total, "unique"=> count($cnt) ) ); echo json_encode($json_array); } else if ($_GET['output'] == "jpeg") { //Start image object $im = imagecreatetruecolor(120, 25); //Get background colour if (strlen($_GET['bg']) === 6) { $bg_hex = str_split($_GET['bg'],2); $bg = imagecolorallocate($im, hexdec($bg_hex[0]), hexdec($bg_hex[1]), hexdec($bg_hex[2])); } else $bg = imagecolorallocate($im, 255, 255, 255); //Create background fill imagefill($im, 0, 0, $bg); //Get foreground (text) colour if (strlen($_GET['fg']) === 6) { $fg_hex = str_split($_GET['fg'],2);//str_split($_GET['fg'],2); $fg = imagecolorallocate($im, hexdec($fg_hex[0]), hexdec($fg_hex[1]), hexdec($fg_hex[2])); } else $fg = imagecolorallocate($im, 0, 0, 0); //Add text if ($_GET['ct'] == "unique") { if ( ! $_GET['nt']) $text = 'Unique '; $text .= count($cnt); } else { if ( ! $_GET['nt']) $text = 'Visitors '; $text = $total; } imagestring($im, 5, 5, 5, $text, $fg); //Output image header('Content-type: image/jpeg'); imagejpeg($im,NULL,100); imagedestroy($im); } else if ($_GET['output'] == "pixel") { //Single pixel output //Start image object $im = imagecreatetruecolor(1, 1); //Get background colour if (strlen($_GET['bg']) === 6) { $bg_hex = str_split($_GET['bg'],2); $bg = imagecolorallocate($im, hexdec($bg_hex[0]), hexdec($bg_hex[1]), hexdec($bg_hex[2])); } else $bg = imagecolorallocate($im, 0, 0, 0); //Create background fill imagefill($im, 0, 0, $bg); //Output image header('Content-type: image/jpeg'); imagejpeg($im,NULL,100); imagedestroy($im); } else { // Else always output as text echo "Total hits: ".$total."
"; echo "Unique hits: ".count($cnt)."
"; } }