Jump to content

Help with code


intenseone345

Recommended Posts

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>

 

Link to comment
Share on other sites

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";
}

Link to comment
Share on other sites

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);

 

Link to comment
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.