UK PHP MySql Website Hosting

Please choose your currency: Pounds Sterling £ US Dollars $

Menu
 ·  Home
 ·  Open a Reseller Account
 ·  Domain Names
 ·  Web Hosting Accounts
 ·  Online Website Designer New
 ·  Who-is
 ·  Our Price List
 ·  Help/FAQ
 ·  News
 ·  PHP Faq
 ·  PHP/MySQL Links
 ·  Contact Us
 ·  Terms and Conditions
 
 ·  Our Blog / Offsite News
 ·  Money Back Guarantee
 

Server Solutions
 
 ·  Dedicated Servers
 


!! Domain Managment !!
 
 ·  Recover Password
 ·  Manage Global Domains
 ·  Manage UK Domains
 ·  Renew Domain
 



!! New Features !!
 
 ·  Online Website Designer
 ·  Free Webmail
 ·  E-Mail Anti Virus Scanning
 ·  MySQL4.1 Optional Support
 ·  PHP5 Optional Support
 ·  Latest PHPMyAdmin
 ·  Free Multiple FTP Accounts
 ·  Free SpamAssassin Install
 

Join Mail List
 
 

php hosting MySQL hosting
Get Firefox!

php + Secure hosting (SSL)
 

Question :
How do I stop spammers using header injection with my PHP Scripts? (Webmasters)
Answer :
*UPDATE*
System administrators I would recomend visting choon.net php-mail-header Patch. Using this patch will add additional headers into all sent mail, using the php mail command. This will enable you to track spam reports much faster.

Its also advisable to look at installing Suhosin Hardended PHP Patch, this patch adds far greater security to a PHP build. The mail options should slow down spammers and hackers efforts.


--
Spammers have recently been using mail header injection to send spam e-mail from contact forms that have in the past viewed as secure.

If you are a webmaster you can edit your forums to ensure they are secure and safe from spammers

This code is posted on http://uk2.php.net/manual/en/ref.mail.php#59012 by Tim

Anyway, I have several websites that all use a common contact form. Every contact form posts to the same script.

This is how I defend against header injections. (I typically use this script as an include file)

This script requires your html form to use action="post". Make sure this is only used on the script that the html form will be posted to. If you use this script on a regular page request, it will die().

* More error checking should be done when testing posted values for bad strings. Possibly a regular expression...


<?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("domain.com""domain2.com""domain3.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:",
                     
"MIME-Version:",
                     
"Content-Transfer-Encoding:",
                     
"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);
?> 



Categories


 

Questions

Installation
How to install PHP on Apache?
How do I install Apache, MySQL, PHP on Linux?
I am trying to install GD + Truetype with PHP4, but all I get is libgd was not built with TrueType font support
How did you install PHP with --mcrypt and --mhash?
When using GD/PHP to create thumbnails using imagecopyresized the thumbnail quality is not very good.
Can I compile php with mysql without having mysql sources?
How do I install PHP as a CGI?
How can I get PWS (Microsoft Personal Webserver) to work?
I have errors trying to install libxml so I can use --with-dom for PHP (checking for DOM in default path... not found)?
How do I install Sablotron with PHP?
Is there a Windows version of MySQL?
Is there an archive that installs mysql,php4,apache and perl on a windows system?
What do I have to do to convert PHP3 pages to PHP4 pages? Are there any compatibility problems?
I'm trying to compile PHP 4.1.1 on a SunOS 5.8 box as a DSO module with mcrypt 2.4.18 (i.e. libmcrypt.so.4.2.8), I get loads of errors.
Installing MySQL Perl Modules DBI
How do I install Sablotron to work with PHP on Windows?
How do I install the PostGRESQL client librarys so PHP can talk to remote PGSQL servers?
What version should I install?
make install gives an error saying i need LoadModule line in httpd.conf but its already there
Use ereg_replace to replace only the first occurence of a string instead of all?
error: conflicting types for `XML_FEATURE_UNICODE'
How do I stop spammers using header injection with my PHP Scripts? (Server Admin)
How do I install Curl?
Installing ioncobe with php5.2.3 gives the error Failed loading ioncube_loader_lin_5.2.so: ioncube_loader_lin_5.2.so: undefined symbol: zend_hash_destroy
 

Return to the main FAQ list


Registered Address: Waverley Braintree Road Cressing ESSEX CM77 8JE
Company Number:
All prices exclude VAT charged at 17.5%

Email:

Copyright Information
Copyright © 2000-2008 . All Rights Reserved

PHP Hosting