PHP $_SERVER (Super Global) Variable with Example

PHP $_SERVER (Super Global) Variable with Example

PHP $_SERVER: Here, we will find out about a too worldwide variable $_SERVER in PHP with example.

PHP $_SERVER

PHP $_SERVER is a cluster that contains the server-related data like headers, ways, and content areas, a web server passages this data in this exhibit is open through the $_SERVER variable.

PHP $_SERVER superglobal variable is significant and is utilized to get data about the server name, records root, and numerous others. There are numerous components accessible in the $_SERVER superglobal exhibit. We will take a gander at a couple of most ordinarily utilized in the given example.

Example of $_SERVER in PHP

PHP code to exhibit an example of $_SERVER

<?php
	// file name of the present executing script
	echo $_SERVER['PHP_SELF'] . '<br>';
	//the document root of the server
	echo $_SERVER['DOCUMENT_ROOT'] . '<br>';
	//the ip address of the server
	echo $_SERVER['SERVER_ADDR'] . '<br>';
	//the name of the server
	echo $_SERVER['SERVER_NAME'] . '<br>';
	//the method the page is using to request
	echo $_SERVER['REQUEST_METHOD'] . '<br>';
	// the time stamp of the start of the request
	echo $_SERVER['REQUEST_TIME'] . '<br>';
	//used to detect the OS, browser
	echo $_SERVER['HTTP_USER_AGENT'] . '<br>';
	// the current user ip address
	echo $_SERVER['REMOTE_ADDR'];
?>

Output:

/CA2.php
C:/xampp/htdocs
::1
localhost
GET
1558789727
Mozilla/5.0 (Windows NT 10.0; Win64; x64) 
AppleWebKit/537.36 (KHTML, like Gecko) 
Chrome/74.0.3729.169 Safari/537.36
::1

Note: The output depends individually on the PC, so yours might be unique.

Recent Posts

error: Alert: Content is protected!!