Home » PHP

PHP $_SERVER (Super Global) Variable with Example

PHP $_SERVER: Here, we are going to learn about a super global variable $_SERVER in PHP with example.
Submitted by Kongnyu Carine, on May 25, 2019


PHP $_SERVER is an array that contains the server-related information like headers, paths, and script locations, a web server entries this information in this array that is accessible through the $_SERVER variable.

PHP $_SERVER superglobal variable is very important and is used to get information about the server name, documents root, and many others. There are many elements available in the $_SERVER superglobal array. We will look at a few most commonly used in the given example.

Example of $_SERVER in PHP

PHP code to demonstrate example of $_SERVER

	// 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


Mozilla/5.0 (Windows NT 10.0; Win64; x64) 
AppleWebKit/537.36 (KHTML, like Gecko) 
Chrome/74.0.3729.169 Safari/537.36

Note: The output is based on my own computer, so yours may be different.

Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.