RSS Forums RSS
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 555 | Replies: 4
Reply
Join Date: Jul 2007
Posts: 11
Reputation: Luc is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Luc Luc is offline Offline
Newbie Poster

Protecting against spam

  #1  
Jul 25th, 2007
Hi folks,

now i have my form up and running, i would like to get it protected against spammers. I did a google on it but it seems hard for me as a newbie to get it right so i ask for your advice.
Would the following code, inserted after the mail() function work?
$dodgy_strings = array(
                "content-type:"
                ,"mime-version:"
                ,"multipart/mixed"
                ,"bcc:"
);

function is_valid_email($email) {
  return preg_match('#^[a-z0-9.!\#$%&\'*+-/=?^_`{|}~]+@([0-9.]+|([^\s]+\.+[a-z]{2,6}))$#si', $email);
}

function contains_bad_str($str_to_test) {
  $bad_strings = array(
                "content-type:"
                ,"mime-version:"
                ,"multipart/mixed"
		,"Content-Transfer-Encoding:"
                ,"bcc:"
		,"cc:"
		,"to:"
  );
  
  foreach($bad_strings as $bad_string) {
    if(eregi($bad_string, strtolower($str_to_test))) {
      echo "$bad_string found. Suspected injection attempt - mail not being sent.";
      exit;
    }
  }
}

function contains_newlines($str_to_test) {
   if(preg_match("/(%0A|%0D|\\n+|\\r+)/i", $str_to_test) != 0) {
     echo "newline found in $str_to_test. Suspected injection attempt - mail not being sent.";
     exit;
   }
} 

if($_SERVER['REQUEST_METHOD'] != "POST"){
   echo("Unauthorized attempt to access page.");
   exit;
}

if (!is_valid_email($email)) {
  echo 'Invalid email submitted - mail not being sent.';
  exit;
}

contains_bad_str($email);
contains_bad_str($subjectline);
contains_bad_str(body);

contains_newlines($email);
contains_newlines($subjectline);

TIA
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2007
Location: USA
Posts: 3,176
Reputation: Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold 
Rep Power: 15
Solved Threads: 314
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Posting Sensei

Re: Protecting against spam

  #2  
Jul 25th, 2007
Take a look at ReCaptcha, it might help.
http://recaptcha.net/
Reply With Quote  
Join Date: Jul 2007
Posts: 11
Reputation: Luc is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Luc Luc is offline Offline
Newbie Poster

Re: Protecting against spam

  #3  
Jul 25th, 2007
Ezzaral,

as i understand it, what the user will see are instructions in english. Unfortunately, i'm doing this stuff for a brazilian client and their english over here isn't that good ;-)
Reply With Quote  
Join Date: May 2007
Location: USA
Posts: 3,176
Reputation: Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold 
Rep Power: 15
Solved Threads: 314
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Posting Sensei

Re: Protecting against spam

  #4  
Jul 25th, 2007
Originally Posted by Luc View Post
Ezzaral,

as i understand it, what the user will see are instructions in english. Unfortunately, i'm doing this stuff for a brazilian client and their english over here isn't that good ;-)
Hmm, yeah I don't see anything on the site about internationalized instructions. Sorry =\
Reply With Quote  
Join Date: Jul 2007
Posts: 11
Reputation: Luc is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Luc Luc is offline Offline
Newbie Poster

Re: Protecting against spam

  #5  
Jul 25th, 2007
no worries,

i'll just keep hoping that some php code will resolve it ;-)
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 6:10 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC