Simple PHP problem i think

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
intenseone345
Forum Newbie
Posts: 16
Joined: Sun Dec 20, 2009 3:10 pm

Simple PHP problem i think

Post by intenseone345 »

Hello, i would love some help with this problem, What i have is a simple page with a comments textarea box, when submit is clicked it sends the comment to a seperate php file i have shown below, then it refreshes back to the comment box page and displays the comment in real time and emails me, But i noticed i get slammed to death with drug links and such, So then i added a JAVA submit button and JAVA word filter in the hopes that if they turned off there java, the submit button wont function, but low and behold they must be using a keyboard event to trigger the submit action anyway, so is there anyway to wire in a simple php script on top of the script i have included below, a php word filter that will not pass the data to the "comments open and insert comment to the flatfile" if say the word vi---gra or http or www is found, and perhaps give an alert or just redirect back to the comment input page without listing the comment, im thinking getting the php word trap here were the comment comes in for listing, would be best, as no Onclick or Onkeyup will work with java turned off, any help would be greatly appreciated, here is my php comments insert to flatfile code, that i want to add a php word trap on top of.

php code
<?
/* this part can either be in the same file as the form or it can be in a different file. If you want this in a different file, make the "action" of the form go to that file */

$fc = fopen("comments.txt","a+b"); //opens the file to append new comment -
fputs($fc,$_POST['comments']."\n\n\nNewComment->"); //writes the comments followed by a
fclose($fc); //closes the files

if(sizeof($_POST)) {
$body = "";
while(list($key, $val) = each($HTTP_POST_VARS)) {
$body .= "$key: $val \n";
}
mail("myEmail@myEmail.com", // to
"Subject Line",
$body);

header("Location: myproject.html");
}
oscardog
Forum Contributor
Posts: 245
Joined: Thu Oct 23, 2008 4:43 pm

Re: Simple PHP problem i think

Post by oscardog »

Why not just use a free web captcha?
intenseone345
Forum Newbie
Posts: 16
Joined: Sun Dec 20, 2009 3:10 pm

Re: Simple PHP problem i think

Post by intenseone345 »

Thanks, but that wont work as these people will simply fill out the captha, then submit anything they want, bypassing my "char limiter", "word filter" , "noPaste" and last but not least the java submit button that was not supposed to work if these creeps turn off there java. and instead of being limited to 200 char, the put in 1000.
intenseone345
Forum Newbie
Posts: 16
Joined: Sun Dec 20, 2009 3:10 pm

Re: Simple PHP problem i think

Post by intenseone345 »

How would i go about "Joining" these two scripts shown below, as when i tested them, it just blew past the check word part, and posted the comment anyway, any idea's would be welcome.

php-word trap

<?php

$words = array('badword1', badword2);

if (in_array($words, $post) ) { don't let the user post } else { post the message }

?>

joined to this file "file puts" and email php code and work?

<?
/* this part can either be in the same file as the form or it can be in a

different file. If you want this in a different file, make the "action" of the

form go to that file */

$fc = fopen("comments.txt","a+b"); //opens the file to append new comment -
fputs($fc,$_POST['comments']."\n\n\nNewComment->"); //writes the comments followed by a
fclose($fc); //closes the files

if(sizeof($_POST)) {
$body = "";
while(list($key, $val) = each($HTTP_POST_VARS)) {
$body .= "$key: $val \n";
}

mail("myEmail@myEmail.com", // to
"Subject Line",
$body);

header("Location: myproject.html");
}

// end form processing
?>
MichaelR
Forum Contributor
Posts: 148
Joined: Sat Jan 03, 2009 3:27 pm

Re: Simple PHP problem i think

Post by MichaelR »

intenseone345 wrote:How would i go about "Joining" these two scripts shown below, as when i tested them, it just blew past the check word part, and posted the comment anyway, any idea's would be welcome.
That's because your error check wouldn't fail the test. It checks to see if the entire post is in the array. Which it isn't. You need to check each word, like this:

Code: Select all

 $words = array(
 
    'bad1',
    'bad2',
    'bad3',
 
  );
 
  $continue = true;
 
  foreach ($words as $word) {
 
    if (preg_match('/\b' . $word . '\b/i', $post)) {
      $continue = false;
      exit();
    }
 
  }
 
  if (!$continue) {
    // Bad boy!
  }
 
  else {
    // Post message
  }
intenseone345
Forum Newbie
Posts: 16
Joined: Sun Dec 20, 2009 3:10 pm

Re: Simple PHP problem i think

Post by intenseone345 »

Thankyou, i understand, sometimes more set's of eyes are better than one, when the answer is staring you in the face and you just dont see it, thanks again.
Post Reply