Summary of usage of several predefined variables of php $_ SERVER

  • 2021-07-24 10:31:39
  • OfStack

This article summarizes the use of several php predefined variables, $_ SERVER. Share it for your reference. The details are as follows:

<?php
echo 'documentroot:'.$_SERVER['DOCUMENT_ROOT'].'<br>'; // Root directory , In apache Define in the configuration file of: httpd.conf For example: DocumentRoot "D:/work/php_root"
echo 'httphost:'.$_SERVER['HTTP_HOST'].'<br>';   // Domain names, such as: localhost
echo 'phpself:'.$_SERVER['PHP_SELF'].'<br>';   // The path from the root directory to the file itself
echo 'script filename'.$_SERVER['SCRIPT_FILENAME'].'<br>';   //documentroot+phpself
echo 'request uri'.$_SERVER['REQUEST_URI'].'<br>';   // All URL strings starting from the root directory, including the characters after the question mark
echo 'request method:'.$_SERVER['REQUEST_METHOD'].'<br>';   // Requested method
echo 'name:'.$_REQUEST['name'].'<br>';   // The value of the request parameter
?>

I hope this article is helpful to everyone's PHP programming.


Related articles: