note 66415 added to function.mail

From: Date: Sun, 21 May 2006 21:10:18 +0000
Subject: note 66415 added to function.mail
Groups: php.notes 
Request: Send a blank email to php-notes+get-111793@lists.php.net to get a copy of this message
Here's my way of detecting an attempt to hijack my mail form. <?php #requires PHP 5 or greater $request = array_map('trim',($_SERVER['REQUEST_METHOD'] == "POST") ? $_POST : $_GET) ; //check for spam injection $allfields = implode('',$request) ; $nontext = $request ; unset($nontext['message'] ); $nontextfields = implode ('',$nontext) ; if ((strpos ($nontextfields,"\\r")!==false) || (strpos ($nontextfields,"\\n")!==false) || (stripos ($allfields,"Content-Transfer-Encoding")!==false) || (stripos ($allfields,"MIME-Version")!==false) || (stripos ($allfields,"Content-Type")!==false) || ($request['checkfield']!=$check) || (empty($_SERVER['HTTP_USER_AGENT']))) die('Incorrect request') ; //stop spammers ?> First, I put the data into an array $request, then set up two strings: $allfields, which is just all fields concatenated, then $nontext, which excludes those fields in which \\r\\n is allowed (e.g., the message body). Any form field in which \\r\\n is allowed should be unset in the $nontext array before the second implode function (my message field is called 'message', so I unset that). I also include a hidden field in the form with a preset value ('checkfield', $check), so I can see if something is trying to alter all fields. This is a combination of a lot of things mentioned in the messages below... ---- Server IP: 66.163.161.117 Probable Submitter: 71.143.67.52 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.mail.php Edit -- http://master.php.net/note/edit/66415 Del: integrated -- http://master.php.net/note/delete/66415/integrated Del: useless -- http://master.php.net/note/delete/66415/useless Del: bad code -- http://master.php.net/note/delete/66415/bad+code Del: spam -- http://master.php.net/note/delete/66415/spam Del: non-english -- http://master.php.net/note/delete/66415/non-english Del: in docs -- http://master.php.net/note/delete/66415/in+docs Del: other reasons-- http://master.php.net/note/delete/66415 Reject -- http://master.php.net/note/reject/66415 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#111793) next »