Home  >  Article  >  Backend Development  >  Four examples of php global variable $_SERVER

Four examples of php global variable $_SERVER

WBOY
WBOYOriginal
2016-07-25 08:56:361199browse
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"; //加载版本头信息


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn