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

Four examples of php global variable $_SERVER

WBOY
Release: 2016-07-25 08:56:36
Original
1239 people have browsed it
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 />";
}
?>
Copy after login

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)
        . '.';
?>
Copy after login

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); 
?>
Copy after login

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"; //加载版本头信息
Copy after login


source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template