small php problem

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

small php problem

Post by intenseone345 »

Hello, i had this php script running fine on the server for a year, now all of
a sudden its not working and im getting this error message:

-------------------------------------------------------
Warning: Variable passed to each() is not an array or object in
/home1/website/public_html/maila.php on line 37

Warning: Cannot modify header information - headers already sent by (output
started at /home1/website/public_html/maila.php:37) in
/home1/website/public_html/maila.php on line 45
-------------------------------------------------------
All the script does is filter words from a form, writes them to a flat file,
emails the comment to me then redirects back to display the comment to the
user.
----------------------------------
Here is my code that was working and now does not, i played with it for hours with no luck, if i commented out line 37 then it would work but it sends a blank e-mail to me, any help i would be grateful for, thanks.

Code: Select all

<? 
$post = $_POST['comments'];
if (!$post){
header("Location: webpage.php");
exit();
}
if (strlen($_POST['comments']) > 208) {
header("Location: webpage.php");
exit();
}

$words = array('unwanted words for array put here', );

  $continue = true;

  foreach ($words as $word) {

  if (preg_match('/\b' . $word . '\b/i', $post)) {
      $continue = false;
      header("Location: webpage.php");
      exit();
  
       }

    }

   if (!$continue) {
     echo 'Bad boy!';

   } 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)) {     //<--Line 37
$body .= "$key: $val \n";
}

mail("my-email@aol.com", // to
"Subject Line",
$body);

header("Location: webpage.php");
}

}         //<--Line 48 
Last edited by Benjamin on Mon Jan 10, 2011 10:24 pm, edited 1 time in total.
Reason: Added [syntax=php] tags.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: small php problem

Post by Benjamin »

Just change $HTTP_POST_VARS to $_POST.
Post Reply