Home > Article > Backend Development > Four examples of php global variable $_SERVER
This article introduces an example of the global variable $_SERVER in PHP. Friends in need can refer to it.
Example 1, loop to list the values in the global variable $_SERVER <?php foreach ($_SERVER as $var => $value) { echo "$var => $value <br />"; } ?> Example 2, get the last update time of the file <?php $lastmod = filemtime($_SERVER['SCRIPT_FILENAME']); echo '此文件的最后更新时间 ' . date('l d F Y, \a\t H:i:s T', $lastmod) . '.'; ?> Example 3, get the update date and time of the file <?php $lastmod = filemtime($_SERVER['SCRIPT_FILENAME']); echo '文件更新时间:' . date('l d F Y, \a\t H:i:s T', $lastmod); ?> Example 4, site environment variable information <?php $version = $_SERVER['SITE_VERSION']; if ('members' == $version) { if (!authenticate_user($_POST['username'], $_POST['password'])) { header('Location: http://bbs.it-home.org/'); exit; } } include_once "${version}_header"; //加载版本头信息 |