Php server variables available that might be useful

Php server variables available that might be useful

Online by JSC0d3
April 5, 2016 | | 739 recognitions

Server Variables are those variables which are inside the super global array named $_SERVER available in PHP. There are many server variables in PHP and some of them are very useful for fore developing PHP projects. I’m going to post here some of the very useful server variables available in PHP development.

8 php server variables:

  1. $_SERVER[‘REQUEST_URI’] – It return the URL in to access the page which is executing the script. If you need to type to access the page then $_SERVER[‘REQUEST_URI’] returns “/product.php?id=5”.
  2. $_SERVER[‘DOCUMENT_ROOT’] – Returns the root directory of the server which is specified in the configuration file of server. This variable usually returns the path like “/usr/yoursite/www” in Linux and “D:/xamps/xampp/htdocs” in windows.
  3. $_SERVER[‘HTTP_HOST’] – Returns the host’s name as found in the http header. This variable usually returns the path like “” when the you find “” in browser’s address-bar and return “” when you see in the address-bar. This is quite useful when you’ve to preserve session while making online payment using PHP since session stored for “” is not same as for the “”.
  4. $_SERVER[‘HTTP_USER_AGENT’] – Returns the user agent’s (browser) detail accessing the web page. We can use strpos($_SERVER[“HTTP_USER_AGENT”],”MSIE”) to detect Microsoft Internet explorer or you can use strpos($_SERVER[“HTTP_USER_AGENT”],”Firefox”) to detect firefox browser in PHP.
  5. $_SERVER[‘PHP_SELF’] – Returns the file-name of the currently executing script. Let’s suppose that you’re accessing the URL then $_SERVER[‘PHP_SELF’] returns “/product.php” in your script.
  6. $_SERVER[‘QUERY_STRING’] – Returns the query string if query string is used to access the script currently executing. Query strings are those string which is available after “?” sign.if you use $_SERVER[‘QUERY_STRING’] in the script executing the following URL “” then it returns “id=5&page=product” in your script.
  7. $_SERVER[‘REMOTE_ADDR’] – Returns the IP address of remote machine accessing the current page. But you can’t relie on $_SERVER[‘REMOTE_ADDR’] to get the real IP address of client’s machine. See this article to know how to get real IP addrees in PHP.

  8. $_SERVER[‘SCRIPT_FILENAME’] – Returns the absolute path of the file which is currently executing. It returns path like “var/” in Linux and path like “D:/xampp/xampp/htdocs/test/domain.php” in windows.

JSC0d3's Logo
About JSC0d3

JSC0d3 is an entrepreneur, online marketer, and an employee of an IT company. When not building websites, creating content, or helping customers improve their online business, spend time with their wife and two beautiful children. Although he still feels new in WordPress, he enjoys sharing what he has learned with all of you! If you want to get in touch with him, you can do this through this website.

On the same idea

Posted by | February 9, 2019

WordPress' wp_link_pages() function, used for displaying page links in multi-page posts, lacks one big feature You can display a list of...

Posted by | December 14, 2018

Preliminary step: Testing whether the code complies with the format of a fiscal identification code (CIF) That is, the maximum length should be 10...

Posted by | November 8, 2017

Nowadays, a lot of bloggers choose to remove HTML tag from WordPress websites However, for beginners and newbies in this field, they may feel...

Previous PostBackNext Post

Leave here an impression