intenseone345 Posted January 11, 2011 Share Posted January 11, 2011 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, any help i would be grateful for, thanks. <code> <? $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 </code> Quote Link to comment https://forums.phpfreaks.com/topic/224032-help-with-code/ Share on other sites More sharing options...
DavidAM Posted January 11, 2011 Share Posted January 11, 2011 The second error message is a result of the first error. Since the first error was written to the browser, the header() call fails. So, once you fix the first one, the second one should go away. The first error is caused by the use of $HTTP_POST_VARS. This variable was deprecated a while back. It may be that your host upgraded PHP or otherwise changed the php.ini file so that the variable is no longer defined (see PHP: $_POST - Manual). You should change that to $_POST. It looks like you are using $_POST everywhere else in that code, so it should not be too much trouble. if(sizeof($_POST)) { $body = ""; while(list($key, $val) = each($_POST)) { //<--Line 37 $body .= "$key: $val \n"; } Quote Link to comment https://forums.phpfreaks.com/topic/224032-help-with-code/#findComment-1157710 Share on other sites More sharing options...
QuickOldCar Posted January 11, 2011 Share Posted January 11, 2011 Use <?php instead of shortcode <? Obviously this is not the actual code you are using if was working for a year. $words = array('unwanted words for array put here', ); But if were to do it should be formatted as this $words = array("unwanted","words","for","array","put","here"); Also as a suggestion any time bringing stuff in from arrays or text files is usually good to trim it. You may accidentally have whitespace. trim($word); Lastly, all this is just sitting there each line with no echo's or semicolons at end of lines mail("my-email@aol.com", // to "Subject Line", $body); so try mail('my-email@aol.com', 'Subject Line', $body); Quote Link to comment https://forums.phpfreaks.com/topic/224032-help-with-code/#findComment-1157711 Share on other sites More sharing options...
intenseone345 Posted January 11, 2011 Author Share Posted January 11, 2011 Thank you for the quick help everyone, im on it and will make the changes that you suggested. thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/224032-help-with-code/#findComment-1158120 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.