PHP: Rewrite $HTTP_GET_VARS [deprecated]

0

$HTTP_GET_VADS is deprecated.

However, it is used in older programs. For instance

test_args.php
<?php
// -----------------------------------------------------------------
echo "<html>";
echo '<meta http-equiv="CONTENT-TYPE" content="text/html; charset=utf-8" />';
echo "<body>";
echo "test_args.php<p />";
echo "<h2>テスト</h2>";
$in_vars = "";
while (list($key, $val) = each($HTTP_GET_VARS)) {
    $in_vars    .= $key."=".$val. "<p />";
}
echo $in_vars;
echo "Jun/28/2020<p />";
echo "</body>";
echo "</html>";
// -----------------------------------------------------------------
?>

When I run this program, I get the following logs:

/var/log/apache2/error.log
[Sun Jun 28 20:40:57.834991 2020] [php7:warn] [pid 8012] [client 127.0.0.1:41472] PHP Warning:  Variable passed to each() is not an array or object in /home/uchida/html/data_base_language/test_dir/php/test_args.php on line 10, referer: http://localhost/html/data_base/test_dir/php/

If you modify it as follows, it will work fine.

<?php
// -----------------------------------------------------------------
echo "<html>";
echo '<meta http-equiv="CONTENT-TYPE" content="text/html; charset=utf-8" />';
echo "<body>";
echo "test_args.php<p />";
echo "<h2>テスト</h2>";
$in_vars = "";

// while (list($key, $val) = each($HTTP_GET_VARS)) {
while (list($key, $val) = each($_GET)) {
    $in_vars    .= $key."=".$val. "<p />";
}
echo $in_vars;
echo "Jun/28/2020<p />";
echo "</body>";
echo "</html>";
// -----------------------------------------------------------------
?>

This is the result of executing with the following arguments: test_args.php?aa=12&bb=34&cc=56

test_args_jun28.png

Share:
0
内田 雅智
Author by

内田 雅智

Python3,Node.js,Go,PHP,Nginx,RaspberryPi,Arduino あたりがカバー範囲です。

Updated on June 29, 2020