View file mini-top/go.php

File size: 1.54Kb
<?php
if (isset($_GET['user'])) {
	$user= $_GET['user'];
	
	$fs= filesize('data.txt');
	$f= fopen('data.txt', 'a+');
	fseek($f, 0);
	flock($f, LOCK_EX);
	$tmp= fread($f, $fs);
	$rat= unserialize($tmp);
	if (isset($rat[$user])) {
		if ($rat['dat']!=date('Y.m.d')) {
			foreach ($rat as $a1=>$a2) if ($a1!='dat') $rat[$a1][4]= 0;
			$rat['dat']= date('Y.m.d');
		}
		$rat[$user][4]= $rat[$user][4] + 1;
		$rat[$user][5]= $rat[$user][5] + 1;
		ftruncate($f, 0);
		fwrite($f, serialize($rat));
		flock($f, LOCK_UN);
		fflush($f);
		fclose($f);
	} else {
		flock($f, LOCK_UN);
		fclose($f);
		exit;
	}

	$im = @imagecreatefrompng('icon.png');
	imagecolorallocate($im, 0, 0, 0);
	imagestring($im, 1, 2, 1, 'Hits: '.$rat[$user][4], 0);
	imagestring($im, 1, 2, 9, 'Alls: '.$rat[$user][5], 0);

// Обязательное условие: должен поддерживаться либо .gif, либо .png
	if (function_exists('imagegif')) {
		header('Content-type: image/gif');
		header('Cache-control: no-cache, no-store');
		@imagegif($im);
	} else {
		header('Content-type: image/png');
		header('Cache-control: no-cache, no-store');
		@imagepng($im);
	}
} else {
    $im = imagecreate(28, 10);
    $colBkGround= imagecolorallocate($im, 255, 255, 255);
    imagefilledrectangle($im, 0, 0, 27, 9, $colBkGround);
    $col= imagecolorallocate($im, 0, 0, 0);
    imagestring($im, 1, 2, 1, 'Error', $col);
    imagerectangle($im, 0, 0, 27, 9, $col);
    header('Content-type: image/vnd.wap.wbmp');
    header('Cache-control: no-cache, no-store');
    @imagepng($im);
}
?>