Je suis confronté à quelque chose qui me dépasse complètement et qui n'est pas logique dans ma petite tête, il est évident que c'est moi qui me*de quelque part mais je ne vois pas où ...
Dans ma page d'erreur personnalisée 404.php, j'ai ce code :
<?php
header("X-Robots-Tag: noindex, nofollow, noarchive");
header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1.
header("Pragma: no-cache"); // HTTP 1.0.
header("Expires: ".gmdate('D, d M Y H:i:s', time() - 3600)." GMT"); // Proxies.
header("Content-Type: text/html; charset=utf-8");
$apiUrl = "https://ipinfo.io/%s/json?token=%s";
$ip = $_SERVER["REMOTE_ADDR"];
$apiKey = "0123456789ABCD";
$apiResult = file_get_contents(sprintf($apiUrl, $ip, $apiKey));
$jsonResult = json_decode($apiResult);
if (empty($new_address)) {
// Format date, hour, timezone
$date_hour_timezone = date("Y-m-d H:i:s \U\T\CP", time());
// Page / Folder / File requested
$request = $_SERVER["REQUEST_URI"];
// Format text
$text = "\n".'Error 404 => '.$date_hour_timezone.' => Request : '.$request.' => IP: '.$ip.' => City: '.$jsonResult->city.' => Country: '.$jsonResult->country.' => Lat, Lon: '.$jsonResult->loc;
// Select path log file
$file = $_SERVER["DOCUMENT_ROOT"].'/404.txt';
// Add $text in $file
$fp = fopen($file, "a+");
fputs($fp, $text);
fclose($fp);
}
?>
<!doctype html>
<html>
<head>
<title>PSEUDO.free.fr - 404</title>
</head>
<body>
<style>
body {
background-image: url(/img/404.png);
background-size: cover;
}
</style>
</body>
</html>
Quand je test ça me renvoie ceci :
Warning: file_get_contents(https://ipinfo.io/XXX.XXX.XXX.XXX/json?token=0123456789ABCD): failed to open stream: Connection timed out in /var/www/sdb/8/e/PSEUDO/404.php on line 11
La ligne 11 c'est
$apiResult = file_get_contents(sprintf($apiUrl, $ip, $apiKey));
Si je test l'URL : https://ipinfo.io/XXX.XXX.XXX.XXX/json? ... 456789ABCD dans mon navigateur, je réceptionne un fichier JSON comme ceci :
{
"ip": "XXX.XXX.XXX.XXX",
"hostname": "ld256-1-XXX-XXX-XX-XXX.fbx.proxad.net",
"city": "MaVille",
"region": "Brittany",
"country": "FR",
"loc": "XX.XXXX,-X.XXXX",
"postal": "56XXX",
"org": "AS12322 Free SAS"
}
Donc je comprends pas ... ça fonctionne correctement du navigateur mais pas du serveur et c'est pourtant la même adresse ... J'ai oublié quelque chose mais je ne sais pas quoi ...Merci de vos lumières
