Underc0de

Programación Web => Back-end => Mensaje iniciado por: narupiece en Junio 30, 2010, 12:49:58 PM

Título: Contador de visitas by naru
Publicado por: narupiece en Junio 30, 2010, 12:49:58 PM
hola, aqui les dejo un contador de visitas que hice


Código (php) [Seleccionar]
<?

//Powered By The Legend Hack

$archivo="contador.txt";
$contador="0";
$num_max="9999999";


if ( file_exists ( $archivo )) {

$fp = fopen($archivo,"r");
$contador = fgets($fp, 26);
fclose($fp);

} else {

$fp = fopen($archivo,"w");
fputs($fp,"1");
fclose($fp);

}

++$contador;

$fp = fopen($archivo,"w+");
fwrite($fp, $contador, 26);
fclose($fp);



if ($contador>=$num_max) {

$imagen = imagecreatefromgif("fondo.gif");
$colText = imagecolorallocate($imagen, 255, 255, 255);
imagestring($imagen, 5, 16, 7, $num_max , $colText);
header("Content-type: image/gif");
imagegif($imagen);

}
else
{
$imagen = imagecreatefromgif("fondo.gif");
$colText = imagecolorallocate($imagen, 255, 255, 255);
imagestring($imagen, 5, 16, 7, $contador , $colText);
header("Content-type: image/gif");
imagegif($imagen);
}

?>



aqui la imagen de fondo xD

http://img18.imageshack.us/img18/5143/fondom.gif  (http://img18.imageshack.us/img18/5143/fondom.gif)


bueno, espero que les sirva ;) solo guardan el codigo con el nombre que quieran y lo suben a un hosting junto con la imagen de fondo.

Demo de Contador (http://narupiece.webcindario.com/contador/contador.php)

Saludos! 8)
Título: Re:contador by naru
Publicado por: 303010 en Junio 30, 2010, 01:31:14 PM
Buen aporte, lo provare. ^^.


Saludo..
Título: Re:contador de visitas by naru
Publicado por: linkgl en Julio 03, 2010, 01:34:57 PM
No te líes con:
$fp = fopen($archivo,"r");
$contador = fgets($fp, 26);
fclose($fp);


usa file_get_contents($archivo);