Comment ajouter un filigrane à vos images sans mod_rewrite et permettre de garder une trace des sites utilisant vos images dans un fichier log.
Il sufft de copier ce code dans un fichier à la racine de votre site - disons filigrane.php :
<?php error_reporting(0); // Variables ------------------------------------------------------- // $footer : texte à afficher en bas des images - le filigrane // $log : fichier log // $use_log: inscrire les sites "plagieurs" dans un fichier log ? // $lego : les noms de domaines auxquels ne pas appliquer de filigrane (bool)$use_log = TRUE; (string)$footer = 'source : www.bobotig.fr'; (string)$log = 'plagiat.log'; (array)$lego = array( '127.0.0.1', 'bobotig.fr', 'www.bobotig.fr', '192.168.0.10', '' ); // C'est parti mon kiki ! ------------------------------------------ (string)$file = $_SERVER['DOCUMENT_ROOT'].$_SERVER['REQUEST_URI']; (int)$string_size = 2; (int)$footer_size = 15; (string)$line = "[%s] %s | %s\n"; list($width, $height, $image_type) = getimagesize($file); (array)$hosts = explode('/', $_SERVER['HTTP_REFERER']); (string)$host = $hosts[2]; if ( in_array($host, $lego) ) { header('Content-Type: '.$image_type); readfile($file); } else { // Log des plagiats if ( $use_log === TRUE ) { $line = sprintf($line, date('Y-m-d H:i:s'), $_SERVER['HTTP_REFERER'], $_SERVER['REQUEST_URI'] ); $f = fopen($log, 'a'); if ( $f && fwrite($f, $line) ) fclose($f); } // Ajout du filigrane if ( $image_type == IMAGETYPE_JPEG ) $im = imagecreatefromjpeg($file); elseif ( $image_type == IMAGETYPE_PNG ) $im = imagecreatefrompng($file); elseif ( $image_type == IMAGETYPE_GIF ) $im = imagecreatefromgif($file); else exit; // Le rectangle imagefilledrectangle( $im, 0, $height, $width, $height - $footer_size, imagecolorallocate($im, 49, 49, 156) ); // Le texte imagestring($im, $string_size, $width - (imagefontwidth($string_size) * strlen($footer)) - 2, $height - $footer_size, $footer, imagecolorallocate($im, 255, 255, 255) ); header('Content-Type: '.$image_type); if ( $image_type == IMAGETYPE_JPEG ) imagejpeg($im); elseif ( $image_type == IMAGETYPE_PNG ) imagepng($im); elseif ( $image_type == IMAGETYPE_GIF ) imagegif($im); } ?>
Dans un fichier .htaccess il suffit d'y inscrire :
# Filigrane addhandler Filigrane gif jpg jpeg png action Filigrane /filigrane.phpIl faudra peut-être activé le mod_actions :
a2enmod actions
[2012-01-06 04:03:38] http://www.rl-tech.info/showthread.php/7289-S%C3%A9curis%C3%A9-son-serveur | /contenu/documents/securiser-site-web/images/acid/03.png [2012-01-06 04:03:38] http://www.rl-tech.info/showthread.php/7289-S%C3%A9curis%C3%A9-son-serveur | /contenu/documents/securiser-site-web/images/acid/04.png [2012-01-06 04:03:38] http://www.rl-tech.info/showthread.php/7289-S%C3%A9curis%C3%A9-son-serveur | /contenu/documents/securiser-site-web/images/acid/05.png [2012-01-06 04:03:38] http://www.rl-tech.info/showthread.php/7289-S%C3%A9curis%C3%A9-son-serveur | /contenu/documents/securiser-site-web/images/brutessh/01.png [2012-01-06 04:03:38] http://www.rl-tech.info/showthread.php/7289-S%C3%A9curis%C3%A9-son-serveur | /contenu/documents/securiser-site-web/images/brutessh/02.png [2012-01-06 04:03:38] http://www.rl-tech.info/showthread.php/7289-S%C3%A9curis%C3%A9-son-serveur | /contenu/documents/securiser-site-web/images/webmin/01.png
- version initiale
Contenu modifié le 01/10/2013.
moc.liamg@gitobob -
Philosophie.