{"id":119,"date":"2009-09-20T19:51:08","date_gmt":"2009-09-20T19:51:08","guid":{"rendered":"http:\/\/www.adriangrigoras.com\/blog\/?p=119"},"modified":"2009-09-20T19:51:08","modified_gmt":"2009-09-20T19:51:08","slug":"apache-variables","status":"publish","type":"post","link":"https:\/\/adriangrigoras.com\/blog\/apache-variables\/","title":{"rendered":"Apache variables"},"content":{"rendered":"<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">Server Variables are variables set by Apache, and held inside the super global array \u2018$_SERVER\u2019. They hold very interesting snippits of data available for use, and become very useful when developing PHP projects.<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">$_SERVER[&#8216;REQUEST_URI&#8217;]<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">It return 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[&#8216;REQUEST_URI&#8217;] returns \u201c\/product.php?id=5.<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">$_SERVER[&#8216;DOCUMENT_ROOT&#8217;]<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">Returns the root directory of the server which is specified in the configuration file of server. This variable usually returns the path like \u201c\/usr\/yoursite\/www\u201d in Linux and \u201cD:\/xamps\/xampp\/htdocs\u201d in windows.<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">$_SERVER[&#8216;HTTP_HOST&#8217;]<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">Returns the host\u2019s name as found in the http header. This variable usually returns the path like \u201cexample.com\u201d when the you find \u201chttp:\/\/example.com\u201d in browser\u2019s address-bar and return \u201cwww.example.com\u201d when you see http:\/\/www.example.com in the address-bar. This is quite useful when you\u2019ve to preserve session while making online payment using PHP since session stored for \u201chttp:\/\/example.com\u201d is not same as for the \u201chttp:\/\/www.example.com\u201d.<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">$_SERVER[&#8216;HTTP_USER_AGENT&#8217;]<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">Returns the user agent\u2019s (browser) detail accessing the web page. We can use strpos($_SERVER[&#8220;HTTP_USER_AGENT&#8221;],\u201dMSIE\u201d) to detect Microsoft Internet explorer or you can use strpos($_SERVER[&#8220;HTTP_USER_AGENT&#8221;],\u201dFirefox\u201d) to detect firefox browser in PHP.<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">$_SERVER[&#8216;PHP_SELF&#8217;]<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">Returns the file-name of the currently executing script. Let\u2019s suppose that you\u2019re accessing the URL http:\/\/www.example.com\/product.php?id=5 then $_SERVER[&#8216;PHP_SELF&#8217;] returns \u201c\/product.php\u201d in your script.<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">$_SERVER[&#8216;QUERY_STRING&#8217;]<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">Returns the query string if query string is used to access the script currently executing. Query strings are those string which is available after \u201c?\u201d sign.if you use $_SERVER[&#8216;QUERY_STRING&#8217;] in the script executing the following URL \u201chttp:\/\/www.example.com\/index.php?id=5&amp;amp;page=product\u201d then it returns \u201cid=5&amp;amp;page=product\u201d in your script.<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">$_SERVER[&#8216;REMOTE_ADDR&#8217;]<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">Returns the IP address of remote machine accessing the current page. But you can\u2019t relie on $_SERVER[&#8216;REMOTE_ADDR&#8217;] to get the real IP address of client\u2019s machine.<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">$_SERVER[&#8216;SCRIPT_FILENAME&#8217;]<\/div>\n<div id=\"_mcePaste\" style=\"position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;\">Returns the absolute path of the file which is currently executing. It returns path like \u201cvar\/example.com\/www\/product.php\u201d in Linux and path like \u201cD:\/xampp\/xampp\/htdocs\/test\/example.php\u201d in windows.<\/div>\n<p>Server Variables are variables set by Apache, and held inside the super global array \u2018$_SERVER\u2019. They hold very interesting snippits of data available for use, and become very useful when developing PHP projects.<\/p>\n<p><strong><em>$_SERVER[&#8216;REQUEST_URI&#8217;]<\/em><\/strong><\/p>\n<p>It return 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[&#8216;REQUEST_URI&#8217;] returns \u201c\/product.php?id=5.<\/p>\n<p><strong><em>$_SERVER[&#8216;DOCUMENT_ROOT&#8217;]<\/em><\/strong><\/p>\n<p>Returns the root directory of the server which is specified in the configuration file of server. This variable usually returns the path like \u201c\/usr\/yoursite\/www\u201d in Linux and \u201cD:\/xamps\/xampp\/htdocs\u201d in windows.<\/p>\n<p><strong><em>$_SERVER[&#8216;HTTP_HOST&#8217;]<\/em><\/strong><\/p>\n<p>Returns the host\u2019s name as found in the http header. This variable usually returns the path like \u201cexample.com\u201d when the you find \u201chttp:\/\/example.com\u201d in browser\u2019s address-bar and return \u201cwww.example.com\u201d when you see http:\/\/www.example.com in the address-bar. This is quite useful when you\u2019ve to preserve session while making online payment using PHP since session stored for \u201chttp:\/\/example.com\u201d is not same as for the \u201chttp:\/\/www.example.com\u201d.<\/p>\n<p><strong><em>$_SERVER[&#8216;HTTP_USER_AGENT&#8217;]<\/em><\/strong><\/p>\n<p>Returns the user agent\u2019s (browser) detail accessing the web page. We can use strpos($_SERVER[&#8220;HTTP_USER_AGENT&#8221;],\u201dMSIE\u201d) to detect Microsoft Internet explorer or you can use strpos($_SERVER[&#8220;HTTP_USER_AGENT&#8221;],\u201dFirefox\u201d) to detect firefox browser in PHP.<\/p>\n<p><strong><em>$_SERVER[&#8216;PHP_SELF&#8217;]<\/em><\/strong><\/p>\n<p>Returns the file-name of the currently executing script. Let\u2019s suppose that you\u2019re accessing the URL http:\/\/www.example.com\/product.php?id=5 then $_SERVER[&#8216;PHP_SELF&#8217;] returns \u201c\/product.php\u201d in your script.<\/p>\n<p><strong><em>$_SERVER[&#8216;QUERY_STRING&#8217;]<\/em><\/strong><\/p>\n<p>Returns the query string if query string is used to access the script currently executing. Query strings are those string which is available after \u201c?\u201d sign.if you use $_SERVER[&#8216;QUERY_STRING&#8217;] in the script executing the following URL \u201chttp:\/\/www.example.com\/index.php?id=5&amp;amp;page=product\u201d then it returns \u201cid=5&amp;amp;page=product\u201d in your script.<\/p>\n<p><strong><em>$_SERVER[&#8216;REMOTE_ADDR&#8217;]<\/em><\/strong><\/p>\n<p>Returns the IP address of remote machine accessing the current page. But you can\u2019t relie on $_SERVER[&#8216;REMOTE_ADDR&#8217;] to get the real IP address of client\u2019s machine.<\/p>\n<p><strong><em>$_SERVER[&#8216;SCRIPT_FILENAME&#8217;]<\/em><\/strong><\/p>\n<p>Returns the absolute path of the file which is currently executing. It returns path like \u201cvar\/example.com\/www\/product.php\u201d in Linux and path like \u201cD:\/xampp\/xampp\/htdocs\/test\/example.php\u201d in windows.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Server Variables are variables set by Apache, and held inside the super global array \u2018$_SERVER\u2019. They hold very interesting snippits of data available for use, and become very useful when developing PHP projects. $_SERVER[&#8216;REQUEST_URI&#8217;] It return 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\u2026 <span class=\"read-more\"><a href=\"https:\/\/adriangrigoras.com\/blog\/apache-variables\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-119","post","type-post","status-publish","format-standard","hentry","category-apache"],"_links":{"self":[{"href":"https:\/\/adriangrigoras.com\/blog\/wp-json\/wp\/v2\/posts\/119","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/adriangrigoras.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/adriangrigoras.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/adriangrigoras.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/adriangrigoras.com\/blog\/wp-json\/wp\/v2\/comments?post=119"}],"version-history":[{"count":0,"href":"https:\/\/adriangrigoras.com\/blog\/wp-json\/wp\/v2\/posts\/119\/revisions"}],"wp:attachment":[{"href":"https:\/\/adriangrigoras.com\/blog\/wp-json\/wp\/v2\/media?parent=119"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/adriangrigoras.com\/blog\/wp-json\/wp\/v2\/categories?post=119"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/adriangrigoras.com\/blog\/wp-json\/wp\/v2\/tags?post=119"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}