搜索
首页php教程php手册PHP $_SERVER详细用法分析

PHP $_SERVER详细用法分析

Argument           Result

PHP_SELF           Returns the path and filename of the current script
SERVER_PROTOCOL    Returns the name and revision of the page-requested protocol
REQUEST_METHOD     Returns the request method used to access the page
REQUEST_TIME       Returns the timestamp from the beginning of the request
DOCUMENT_ROOT      Returns the root directory of the current script
HTTP_REFERER       Returns the page address that referred to the current page
HTTP_USER_AGENT    Returns the user agent of the header from the current request
REMOTE_ADDR        Returns the IP address of the current user
REMOTE_PORT        Returns the port of the user's machine that is accessing the page
SCRIPT_FILENAME    Returns the absolute filename from the current script
SCRIPT_NAME        Returns the path of the current script

<?php教程 if ($_SERVER['REQUEST_METHOD'] == 'GET') { 
<form action="<?php echo $_SERVER['SCRIPT_NAME'] " method="post">
What is your first name?
<input type="text" name="first_name" />
<input type="submit" value="Say Hello" />
</form>
<?php } else {
    echo 'Hello, ' . $_POST['first_name'] . '!';
}

获取用户的IP地址

<?php
$address = $_SERVER['REMOTE_ADDR'];
$referer = $_SERVER['HTTP_REFERER'];
$browser = $_SERVER['HTTP_USER_AGENT'];
$file = fopen("log.html",  "a"); 
$time = date("H:i dS F");
fwrite( $file, "<b>Time:</b> $time<br>" );
if( $address != null)
{
  fwrite( $file, "<b>IP Address:</b> $address <br>");
} 
if( $referer != null)
{
  fwrite( $file, "<b>Referer:</b> $referer<br>");  
}
fwrite( $file, "<b>Browser:</b> $browser<br/><hr>"); 
fclose($file);

脚本显示方法

<?php 
$lastmod = filemtime($_SERVER['SCRIPT_FILENAME']);
echo 'file was updated on ' . date('l d F Y, at H:i:s T', $lastmod); 

 

获取服务器时间

<?php
  
  $lastmod = filemtime($_SERVER['SCRIPT_FILENAME']);
  echo 'This file was last updated on '
        . date('l d F Y, at H:i:s T', $lastmod)
        . '.';

 

本文地址:

转载随意,但请附上文章地址:-)

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

EditPlus 中文破解版

EditPlus 中文破解版

体积小,语法高亮,不支持代码提示功能

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

Atom编辑器mac版下载

Atom编辑器mac版下载

最流行的的开源编辑器