Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Last active June 6, 2019 23:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/bf5a257e08749cf1aa2d73c238a91fde to your computer and use it in GitHub Desktop.
Save parzibyte/bf5a257e08749cf1aa2d73c238a91fde to your computer and use it in GitHub Desktop.
<?php
# Para obtener la fecha correcta hay que poner la zona horaria
date_default_timezone_set("America/Mexico_City");
$fechaYHora = date("Y-m-d H:i:s");
# Si no hay REMOTE_ADDR entonces ponemos "Desconocida"
$ip = empty($_SERVER["REMOTE_ADDR"]) ? "Desconocida" : $_SERVER["REMOTE_ADDR"];
# Formatear mensaje
$mensaje = sprintf("La IP %s accedió en %s%s", $ip, $fechaYHora, PHP_EOL);
# Y adjuntarlo o escribirlo en accesos.log
file_put_contents("accesos.log", $mensaje, FILE_APPEND);
# Ya registramos la ip, ahora seguimos con el flujo normal ;)
# Indicar que vamos a servir una imagen jpeg
header('Content-Type: image/jpeg');
header("Content-Transfer-Encoding: Binary");
# Leer la imagen del perro
readfile("perro.jpg");
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment