Project / Support Center
Welcome, Guest. Please login or register. November 29, 2020, 08:47: PM
Home Help Search Login Register
D-Web Web Site Creator D - Web Web Site Creator On-line HTML Editor No Programming knowledge required. Web Global Net PayPal-Cart Shopping Cart System PayPal - Kart Shopping Cart System for E-Commerce over the internet, that's easy to use. Web Global Net Newsletter Manager Newsletter Manager On-line Newsletter Creator with Email Subscriber Management.
Ring Central Discount
Web Global Net Web Application & Web Development Project Center  |  Technical Issues  |  php related  |  Topic: 8 Useful server variables available in PHP 0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] Go Down Send this topic Print
Author Topic: 8 Useful server variables available in PHP  (Read 213 times)
admin
Administrator
******
Offline Offline

Posts: 208


« on: September 21, 2020, 11:20: PM »

When you use it as a dynamic variable it will be entered into your script or email as {SERVER.HTTP_HOST}

$_SERVER['REQUEST_URI']
It returns the URL in to access the page which is executing the script.
If you need to type http://www.example.com/product.php?id=5 to access the page then $_SERVER['REQUEST_URI'] returns /product.php?id=5″.

$_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.

$_SERVER['HTTP_HOST']
Returns the hostís name as found in the http header.
This variable usually returns the path like example.com when you find http://example.com in browsers address-bar and return www.example.com when you see http://www.example.com in the address bar.

This is quite useful when you've to preserve session while making an online payment using PHP since session stored for http://example.com is not same as for the http://www.example.com.

$_SERVER['HTTP_USER_AGENT']
Returns the user agents (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.

$_SERVER['PHP_SELF']
Returns the file-name of the currently executing script.
Letís suppose that youíre accessing the URL http://www.example.com/product.php?id=5 then $_SERVER['PHP_SELF'] returns /product.php in your script.

$_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 the ? sign. If you use $_SERVER['QUERY_STRING'] in the script executing the following URL http://www.example.com/index.php?id=5&page=product then it returns id=5&page=product in your script.

$_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.

$_SERVER['SCRIPT_FILENAME']
Returns the absolute path of the file which is currently executing.
It returns path like var/example.com/www/product.php in Linux and path like D:/xampp/xampp/htdocs/test/example.php in windows.
Report to moderator   Logged

The Unknown Webmaster
Pages: [1] Go Up Send this topic Print 
Web Global Net Web Application & Web Development Project Center  |  Technical Issues  |  php related  |  Topic: 8 Useful server variables available in PHP « previous next »
Jump to:  


Login with username, password and session length
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!