Jump to content

Recommended Posts

Hello, can anyone tell me why this php word trap fails to work,

and the trigger words get blow right past, and the comments get posted anyway?

heres the php code im testing on a server.

 

<?php

$words = array(

 

  'murmer',

  'frog',

  'bat',

 

    );

 

  $continue = true;

 

  foreach ($words as $word) {

 

  if (preg_match('/\b' . $word . '\b/i', $post)) {

      $continue = false;

      exit();

      }

 

    }

 

  if (!$continue) {

    // Bad boy!

  }

 

  else {

    // Post message

  }

$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: mysite.html");

}

 

// end form processing

?>

 

Link to comment
https://forums.phpfreaks.com/topic/185828-help-with-php-code/
Share on other sites

if im not mistaken this should work:

$words = array(

   'murmer',
   'frog',
   'bat',

    );
  
  $continue = true;
  
  foreach ($words as $word) {

  if (preg_match('/\b' . $word . '\b/i', $post)) {
      $continue = false;
      exit();
      }
   
    }
  
   if (!$continue) {
     // Bad boy!
   }
  
   else {
     // Post message
$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: mysite.html");
}
   }

Link to comment
https://forums.phpfreaks.com/topic/185828-help-with-php-code/#findComment-981240
Share on other sites

No, it still failed to work, this time it just showed a page with all the code on it, let me ask, would permission settings have anything to do with the word validator not working? thanks

 

this is what got displayed when i tryed it out your way.

 

$words = array( 'murmer', 'frog', 'bat', ); $continue = true; foreach ($words as $word) { if (preg_match('/\b' . $word . '\b/i', $post)) { $continue = false; exit(); } } if (!$continue) { // Bad boy! } else { // Post message $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: mysite.html"); } }

Link to comment
https://forums.phpfreaks.com/topic/185828-help-with-php-code/#findComment-981249
Share on other sites

Using your code and altering it to give some test output it works OK

 

//$post = 'this is a whisper from a flicker';

$post = 'this is a murmer from a frog';

$words = array(

 

  'murmer',

  'frog',

  'bat',

 

    );

 

  $continue = true;

 

  foreach ($words as $word) {

 

  if (preg_match('/\b' . $word . '\b/i', $post)) {

      $continue = false;

      echo 'word found!';

      exit();

      }

 

    }

 

  if (!$continue) {

    echo 'Bad boy!';

  }

 

  else {

    echo 'Post message';

  }

 

So, is $post a var or an array, probably an array? preg_match wont do an array. Try this:

$post = $_POST['comments'];

Link to comment
https://forums.phpfreaks.com/topic/185828-help-with-php-code/#findComment-981302
Share on other sites

Hello, when i tested this php script below i got the following error message,

 

ERROR SHOWN ON BROWSER:

------------------------

Post message

Warning: Cannot modify header information - headers already sent by

(output started at /hermes/bosweb/web176/b1761/ipw.tomagr/public_html/maila.php:23)

in /hermes/bosweb/web176/b1761/ipw.tomagr/public_html/maila.php on line 39

------------------------

 

The code is in its own page just as its shown below, simple word check, then post the comments

to a flat file and emails me with posted comment.

the, $post = $_POST['comments']; reffers to the form on another page that the

comments are comming from. want to know what im doing wrong in this script?

 

All my attempts to get both "word filter" and "write to flat file" to work together have failed,

CAN anyone show me how they would structure the code above to make them work together,

They work fine as seperate scripts, But not as one whole script,

im no php expert and thats why im asking anyone, remove what you think needs to go. :'(

Thanks

 

the php script :

 

<?

$post = $_POST['comments'];

$words = array('murmer', 'frog', 'bat', );

 

$continue = true;

 

foreach ($words as $word) {

 

if (preg_match('/\b' . $word . '\b/i', $post)) {

$continue = false;

header("Location: mysite.html");

exit();

 

}

 

}

 

if (!$continue) {

echo 'Bad boy!';

}

 

else {

echo 'Post message';

}

$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: mysite.html");

}

 

// end form processing

?>

Link to comment
https://forums.phpfreaks.com/topic/185828-help-with-php-code/#findComment-981875
Share on other sites

I tried removing echo 'Post message';

then i got a "unexpected end error",

also i wanted to also get rid of the if (!$continue) {

    echo 'Bad boy!';

but still get the same ERRor message, I think its the way im ending one script and entering the other, got to do it without errors and get rid of the echo's

Link to comment
https://forums.phpfreaks.com/topic/185828-help-with-php-code/#findComment-981938
Share on other sites

OK Solved, here is a tested and working php script to perform the following for those interested.

 

Basic word filter that kills comment all together if you are getting bombed with via gra adds and such, after validation, it inputs to a flat file data base and can be called to display comments in text area, i did some script to make text area always scroll to bottom to show most recent comments, And emails you with the comment submitted.

 

php script:

 

<?

$post = $_POST['comments'];

$words = array('murmer', 'frog', 'bat', ); //add your trigger words here.

 

$continue = true;

 

foreach ($words as $word) {

 

if (preg_match('/\b' . $word . '\b/i', $post)) {

$continue = false;

header("Location: mysite.html"); //if user enters unwanted text, script redirects

exit(); //back to comment display box without adding

//offenders comments, such as urls or via gra adds

}

 

}

 

if (!$continue) {

echo 'Bad boy!'; //this is useless here

 

} else {

$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", // emails you with new comment in body

"Subject Line",

$body);

 

header("Location: mysite.html"); //refreashes back to video page were more php script

} //shows new comment in real time

 

} 8)

-------------------------------------

Thousand different paths,

So many sterile ends,

I chose the Devil's path,

 

Never shall the sun kiss my face,

And caress me with it's burning light,

For I dwell in the shadows,

And sleep side by side with death....

-------------------------------------

Link to comment
https://forums.phpfreaks.com/topic/185828-help-with-php-code/#findComment-982001
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.