ISN (services de réseaux sociaux internationaux - applications interactives et sites web dynamiques)



Intelligent 404 Handler


 

 
<?php 
/* 
Errors in Client 
400 Bad syntax 
401 Unauthorized 
402 Not Used (Payment Granted) 
403 Forbidden 
404 Not Found 
 
Errors in Server 
500 Internal Error 
501 Not Implemented 
502 Overloaded 
503 Gateway Timeout 
To call the scripts add the following to your .htaccess file. 
 
ErrorDocument 404 /track.php 
 
*/ 
//choose the record either of the following statements 
//depending on what your host provides 
$file404 = $_SERVER['REDIRECT_ERROR_NOTES']."\n"; 
//or 
$file404 = $_SERVER['REDIRECT_URL'] . "\n"; 
$filename = '/var/users/mysite/htdocs/history404.txt'; 
 
if (file_exists($filename)) 
    $filecontents = file($filename); 
    $add = (!in_array($file404, $filecontents)); 
else $add = true; 
 
if ($add) 
    $fp = fopen($filename, 'a'); 
    $write = fputs($fp, $file404); 
    fclose($fp); 
    $body = ''; 
    $reportvars = array('REDIRECT_ERROR_NOTES','HTTP_HOST', 'HTTP_REFERER', 'HTTP_USER_AGENT', 'HTTP_FROM', 
        'REDIRECT_URL', 'REDIRECT_REQUEST_METHOD', 'REDIRECT_STATUS','REQUEST_URI','QUERY_STRING', 
        'REMOTE_ADDR', 'REMOTE_PORT'); 
    foreach($reportvars as $key) $body .= "$key: {$_SERVER[$key]}\n"; 
    mail('webmaster@mysite.com','404:' . $_SERVER['REDIRECT_URL'],$body); 
 
$revbits = explode('.',strrev($_SERVER['REDIRECT_URL'])); 
 
$pages['html'] = array('html','htm','php','txt'); 
$pages['special'] = array('css', 'js'); 
 
$ext = strrev($revbits[0]); 
if (in_array($ext, $pages['html'])) 
    // or show a make a comment form 
    header('Location: /index.php'); 
elseif (in_array($ext, $pages['special'])) 
    //output nothing 
    echo ''; 
else 
    //throw a large image onto the screen so it's easy to hunt down. 
    //change the width and height to a more discreet dimension when live 
    //although if the img has height and width attributes that will overrule 
    //the width and height here 
    $width = 50; 
    $height = 50; 
 
    $image  = ImageCreate($width,$height); 
    $blob = ImageColorAllocate($image,27,48,107); 
 
    if (function_exists("imagegif")) { 
        header ("Content-type: image/gif"); 
        imagegif ($image); 
    } 
    elseif (function_exists("imagejpeg")) { 
        header ("Content-type: image/jpeg"); 
        imagejpeg ($image, "", 0.5); 
    } 
    elseif (function_exists("imagepng")) { 
        header ("Content-type: image/png"); 
        imagepng ($image); 
    } 
    elseif (function_exists("imagewbmp")) { 
        header ("Content-type: image/vnd.wap.wbmp"); 
        imagewbmp ($image); 
    } 
    else 
        // or whatever action should be taken if you don't have GD installed. 
        die("No image support in this PHP server"); 
 
    ImageDestroy($image); 
?>