0

When I run a script in Wamp I get the following Warning Notifications for line 17 and 21. What is this telling me and what can/should be done to resolve the issue ?

Warning: Invalid argument supplied for foreach() in C:\wamp\www\eCardScript\ecard_lib.php on line 17 *Warning:* Invalid argument supplied for foreach() in C:\wamp\www\eCardScript\ecard_lib.php on line 21

<?php
include('htmlMimeMail.php');

function getPostGetVars() {
  global $HTTP_POST_VARS,$HTTP_GET_VARS;
  foreach ($HTTP_POST_VARS as $key => $value) { // This is Line 17
    global $$key;
    $$key = $value;
  }
  foreach ($HTTP_GET_VARS as $key => $value) {  // This is Line 21
    global $$key;
    $$key = $value;
  }
}
?>
Webiter
  • 119
  • 1
  • 10
  • 3
    Don't use HTTP_*_VARS, they have been [deprecated](http://uk.php.net/manual/en/reserved.variables.post.php) for years. – Quentin Dec 19 '11 at 13:12
  • 2
    And don't let user input define the names of globals! That creates a right mess which [is why PHP no longer does it for you](http://php.net/manual/en/security.globals.php)! – Quentin Dec 19 '11 at 13:13
  • Yes, you better use just `$_POST` and `$_GET`. – ArVan Dec 19 '11 at 13:14

2 Answers2

3

Use $_GET and $_POST instead.

http://php.net/manual/en/language.variables.predefined.php

From PHP 5.0.3 long predefined arrays such HTTP_GET_VARS got disabled by default. For backward compatibility you can enable them in php.ini....

Notinlist
  • 16,144
  • 10
  • 57
  • 99
1

$HTTP_POST_VARS and $HTTP_GET_VARS are deprecated. You should use $_POST and $_GET respectively.

Krzysztof
  • 15,900
  • 2
  • 46
  • 76