osCommerce France : Accueil Forum Portail osCommerce France Réponses aux questions Foire aux contributions

Bienvenue invité ( Connexion | Inscription )

> [Script] Anti Spam assez éfficace, A consomer sans modération
Him
posté 16 Jun 2006, 20:26
Message #1


Ceinture bleue OSC
Icône de groupe

Groupe : Membres
Messages : 924
Inscrit : 11-October 05
Lieu : Brux'Hell
Membre no 7419



Bonjour
J'ai découvert il ya quelques mois un bout de code je ne sais plus ou sur la toile, qui se disait "bon" pour bloquer le spam de nos formulaires....

J'ai d'abbord "tester" le script en utilisant une nouvelle adresse e-mail sur ma boutique.
Fort est à croire que sur 3 mois je n'ai reçu que des demandes de client biggrin.gif

(excepté 3 pseudos client africains qui malheureusement spam manuellement...)

alors voila, je vous fait profitez de ce script qui n'est pas difficile à mettre en place.

CODE
<?php

// First, make sure the form was posted from a browser.
// For basic web-forms, we don't care about anything
// other than requests from a browser:  
if(!isset($_SERVER['HTTP_USER_AGENT']))
{
  die ("Forbidden - You are not authorized to view this page");
  exit;
}

// Make sure the form was indeed POST'ed:
//  (requires your html form to use: action="post")
if(!$_SERVER['REQUEST_METHOD'] == "POST")
{
  die ("Forbidden - You are not authorized to view this page");
  exit;  
}

// Host names from where the form is authorized
// to be posted from:
$authHosts = array ("webserviteur.com");

// Where have we been posted from?
$fromArray = parse_url(strtolower($_SERVER['HTTP_REFERER']));

// Test to see if the $fromArray used www to get here.
$wwwUsed = strpos ($fromArray['host'], "www.");

// Make sure the form was posted from an approved host name.
if(!in_array(($wwwUsed === false ? $fromArray['host'] : substr(stristr($fromArray['host'], '.'), 1)), $authHosts))
{  
  //logBadRequest();
  header("HTTP/1.0 403 Forbidden");
   exit;  
}

// Attempt to defend against header injections:
$badStrings = array("Content-Type:",
     "Content-Type: text/plain;",
     "MIME-Version:",
     "Content-Transfer-Encoding:",
     "Content-Transfer-Encoding: 7Bit",
     "bcc:",
     "cc:");

// Loop through each POST'ed value and test if it contains
// one of the $badStrings:
foreach($_POST as $k => $v)
{
  foreach($badStrings as $v2)
  {
   if(strpos($v, $v2) !== false)
   {
    //logBadRequest();
    header("HTTP/1.0 403 Forbidden");
     exit;
   }
  }
}  

// Made it past spammer test, free up some memory
// and continue rest of script:  
unset($k, $v, $v2, $badStrings, $authHosts, $fromArray, $wwwUsed);

// Puis ici ta fonction mail avec tes traitements éventuels !
?>



--------------------
» HimSelf : 24 ans, Bruxelles !

Les logiciels c'est comme le sexe, c'est mieux quand c'est gratuit
# Never trust user inputs
© Liber Dziit
Go to the top of the page
 

Les messages de ce sujet


Reply to this topicStart new topic
1 utilisateur(s) sur ce sujet (1 invité(s) et 0 utilisateur(s) anonyme(s))
0 membre(s) :

 



RSS Version bas débit Nous sommes le : 10th September 2010 - 13:51
Ce site est déclaré auprès de la commision Nationale
de l'Informatique et des Libertés (déclaration n°: 1043896)