-
-
Save parzibyte/cf105c5a763da9ddab6078562d3ee93f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
El contador de visitas más simple | |
https://parzibyte.me/blog | |
*/ | |
$nombreArchivo = "contador.txt"; | |
# Si no existe, lo creamos | |
if (!file_exists($nombreArchivo)) { | |
touch($nombreArchivo); | |
} | |
# Obtenemos su contenido | |
$contenido = trim(file_get_contents($nombreArchivo)); | |
# Si está vacío, lo igualamos a cero | |
if ($contenido == "") { | |
$visitas = 0; | |
} else { | |
# Si no, las visitas son lo que tenga el archivo | |
$visitas = intval($contenido); | |
} | |
# Ya sea que las visitas son 0 o las que hayamos leído, las aumentamos | |
$visitas++; | |
# Y volvemos a escribir el valor en el archivo | |
file_put_contents($nombreArchivo, $visitas); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment