{"id":14683,"date":"2016-09-21T15:43:35","date_gmt":"2016-09-21T12:43:35","guid":{"rendered":"http:\/\/www.webcodegeeks.com\/?p=14683"},"modified":"2018-01-09T10:27:54","modified_gmt":"2018-01-09T08:27:54","slug":"php-global-variables-example","status":"publish","type":"post","link":"https:\/\/www.webcodegeeks.com\/php\/php-global-variables-example\/","title":{"rendered":"PHP Global Variables Example"},"content":{"rendered":"<p>In this example we will learn about PHP global variables, what they are and how to use them.\u00a0Variables are an integral part of any programming language. They are used to hold information about the programming context.<\/p>\n<p>Depending on where the variable is declared, it may be visible or invisible in other parts of the script(the scope of the variable can vary).\u00a0Global Variables or superglobals are visible from any part of the PHP script(they are visible in all scopes)<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n[ulp id=&#8217;8njY7i2QRy6sg8pg&#8217;]<br \/>\n&nbsp;<br \/>\nFor this example we will use:<\/p>\n<ol>\n<li>A computer with PHP&gt;= 5.5 installed<\/li>\n<li>notepad++<\/li>\n<\/ol>\n<h2>1. Global Variables or superglobals<\/h2>\n<p>Superglobals were introduced in PHP 4.1.0. The superglobals are:<\/p>\n<ul>\n<li>$GLOBALS<\/li>\n<li>$_SERVER<\/li>\n<li>$_REQUEST<\/li>\n<li>$_POST<\/li>\n<li>$_GET<\/li>\n<li>$_FILES<\/li>\n<li>$_ENV<\/li>\n<li>$_COOKIE<\/li>\n<li>$_SESSION<\/li>\n<\/ul>\n<h3>1.1 $GLOBALS<\/h3>\n<p>The <code>$GLOBALS<\/code> superglobal is an associative array which references all global variables in the script. The name of the variable is the key for <code>$GLOBALS<\/code> associative array.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>index.php<\/em><\/span><\/p>\n<pre class=\"brush:php; highlight:[6,7]\">  \r\n&lt;?php\r\n$des=\"PHP is a great scripting language.\";\r\n\r\nfunction check(){\r\n$des=\"Java is a great programming language, heard java 9 will be out soon.\";\r\necho \"$des&lt;br&gt;\";\/\/ we print the local variable\r\necho $GLOBALS[\"des\"];\/\/ we print the global variable\r\n\r\n}\r\ncheck();\r\n?&gt;\r\n<\/pre>\n<p>In line six and seven we print both local variable and global variable.<\/p>\n<h3>1.2 $_SERVER<\/h3>\n<p>The <code>$_SERVER<\/code> holds server information. Information such as headers, paths and script location.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>index2.php<\/em><\/span><\/p>\n<pre class=\"brush:php;\">  \r\n &lt;!DOCTYPE html&gt; \r\n&lt;html lang=en&gt;\r\n\t&lt;head&gt;\r\n\t&lt;style&gt;\r\n\thtml, body{\r\n\twidth:100%;\r\n\theight:100%;\r\n\tmargin:0%;\r\n\tfont-family:\"helvetica\",\"verdana\",\"calibri\", \"san serif\";\r\n\toverflow:hidden;\r\n\tpadding:0%;\r\n\tborder:0%;\r\n\t}\r\n\t \r\n\t&lt;\/style&gt;\r\n\t \t\t&lt;meta charset=\"utf-8\" \/&gt;\r\n\t\t&lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, target-densitydpi=device-dpi\"\/&gt;\r\n\t\r\n\t&lt;title&gt;PHP GLOBAL EXAMPLE&lt;\/title&gt;\r\n\t\r\n\t&lt;\/head&gt;\r\n\t&lt;body&gt;\r\n&lt;?php\r\necho $_SERVER [ 'PHP_SELF' ];\/\/ holds the filename about the current executing script\r\necho \"&lt;br&gt;\" ;\r\necho $_SERVER [ 'SERVER_ADDR' ];\/\/holds the ip address of the server which the current script is executing\r\necho \"&lt;br&gt;\" ;\r\necho $_SERVER [ 'SERVER_NAME' ];\/\/ The name of the server host under which the current script is executing.\r\necho \"&lt;br&gt;\" ;\r\necho $_SERVER [ 'REQUEST_METHOD' ];\/\/ Which request method was used to access the page; i.e. ' GET', ' POST \r\necho \"&lt;br&gt;\" ;\r\necho $_SERVER [ 'REQUEST_TIME' ];\r\necho \"&lt;br&gt;\" ;\/\/ The timestamp of the start of the request. Available since PHP 5.1.0.\r\necho $_SERVER [ 'HTTP_HOST' ];\/\/ Contents of the Host: header from the current request, if there is one.\r\necho \"&lt;br&gt;\" ;\r\nif(isset($_SERVER [ 'HTTP_REFERER' ] ))\r\necho $_SERVER [ 'HTTP_REFERER' ];\/\/ The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this\r\necho \"&lt;br&gt;\" ;\r\necho $_SERVER [ 'HTTP_USER_AGENT' ];\/\/ Contents of the User-Agent: header from the current request, if there is one. This is a string denoting the user agent being which is accessing the page.\r\necho \"&lt;br&gt;\" ;\r\necho $_SERVER [ 'SCRIPT_NAME' ];\/\/ Contains the current script's path.\r\n?&gt;\r\n\t&lt;\/body&gt;\r\n\t&lt;\/html&gt;\r\n<\/pre>\n<p>The comments in the code explains the meaning of each superglobal variable.\u00a0The list below contains some elements that can go inside $_SERVER:<br \/>\n<b><br \/>\nNote: You may or may not find any of the following elements in $_SERVER .<br \/>\n<\/b><\/p>\n<ul>\n<li>SERVER_SOFTWARE: Server identification string, given in the headers when responding to requests.<\/li>\n<li>SERVER_PROTOCOL: Name and revision of the information protocol via which the page was requested. i.e. &#8216; HTTP\/1.0 &#8216;<\/li>\n<li>REQUEST_TIME: The timestamp of the start of the request. Available since PHP 5.1.0.<\/li>\n<li>REQUEST_TIME_FLOAT: The timestamp of the start of the request, with microsecond precision. Available since<br \/>\nPHP 5.4.0.<\/li>\n<li>QUERY_STRING: The query string, if any, via which the page was accessed.<\/li>\n<li>HTTP_CONNECTION: Contents of the Connection: header from the current request, if there is one. Example: &#8216; Keep-Alive &#8216;.<\/li>\n<li>HTTP_REFERER: The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the<br \/>\nability to modify HTTP_REFERER as a<br \/>\nfeature. In short, it cannot really be trusted.<\/li>\n<li>SERVER_PORT: The port on the server machine being used by the web server for communication. For default setups, this will be &#8216; 80 &#8216;; using SSL, for<br \/>\ninstance, will change this to whatever your defined secure HTTP port is.<\/li>\n<\/ul>\n<h3>1.3 $_REQUEST<\/h3>\n<p>This superglobal variable holds the contents of<code>$_GET<\/code> , <code>$_POST<\/code> and <code>$_COOKIE<\/code><\/p>\n<p><span style=\"text-decoration: underline;\"><em>index3.php<\/em><\/span><\/p>\n<pre class=\"brush:php;\">  \r\n&lt;!DOCTYPE html&gt; \r\n&lt;html lang=eng&gt;\r\n\t&lt;head&gt;\r\n\t&lt;style&gt;\r\n\thtml, body{\r\n\twidth:100%;\r\n\theight:100%;\r\n\tmargin:0%;\r\n\tfont-family:\"helvetica\",\"verdana\",\"calibri\", \"san serif\";\r\n\toverflow:hidden;\r\n\tpadding:0%;\r\n\tborder:0%;\r\n\t}\r\n\t \r\n\t&lt;\/style&gt;\r\n\t \t\t&lt;meta charset=\"utf-8\" \/&gt;\r\n\t\t&lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, target-densitydpi=device-dpi\"\/&gt;\r\n\t\r\n\t&lt;title&gt;HTML Form&lt;\/title&gt;\r\n\t\r\n\t&lt;\/head&gt;\r\n&lt;body&gt;&lt;?php\r\nif ($_SERVER['REQUEST_METHOD' ] == 'POST' ){\r\necho $_REQUEST['name'].\"&lt;br&gt;\";\r\necho $_REQUEST['occu'];\r\n\r\n}\r\nelse{\r\n?&gt;\r\n&lt;form action=&lt;? echo $_SERVER [ 'PHP_SELF' ]; ?&gt; method =\"POST\"&gt;\r\n&lt;label for=name&gt;First name&lt;\/label&gt;&lt;br&gt;\r\n&lt;input type =\"text\" name =\"name\" id=name required&gt;\r\n&lt;br&gt;&lt;br&gt;\r\n&lt;label for=occu&gt;Occupation&lt;\/label&gt;&lt;br&gt;\r\n&lt;input type =\"text\" name =\"occu\" required&gt;&lt;br&gt;&lt;br&gt;\r\n&lt;input type=\"submit\" value=submit&gt;\r\n&lt;\/form&gt;\r\n&lt;?php\r\n}\r\n?&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<h3>1.4 $_POST<\/h3>\n<p>The $_POST superglobal associative array is used to access all the information sent using the POST method.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>index4.php<\/em><\/span><\/p>\n<pre class=\"brush:php;\">  \r\n&lt;!DOCTYPE html&gt; \r\n&lt;html lang=eng&gt;\r\n\t&lt;head&gt;\r\n\t&lt;style&gt;\r\n\thtml, body{\r\n\twidth:100%;\r\n\theight:100%;\r\n\tmargin:0%;\r\n\tfont-family:\"helvetica\",\"verdana\",\"calibri\", \"san serif\";\r\n\toverflow:hidden;\r\n\tpadding:0%;\r\n\tborder:0%;\r\n\t}\r\n\t \r\n\t&lt;\/style&gt;\r\n\t \t\t&lt;meta charset=\"utf-8\" \/&gt;\r\n\t\t&lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, target-densitydpi=device-dpi\"\/&gt;\r\n\t\r\n\t&lt;title&gt;HTML Form&lt;\/title&gt;\r\n\t\r\n\t&lt;\/head&gt;\r\n&lt;body&gt;&lt;?php\r\nif ($_SERVER['REQUEST_METHOD' ] == 'POST' ){\r\necho $_POST['name'].\"&lt;br&gt;\";\r\necho $_POST['occu'];\r\n\r\n}\r\nelse{\r\n?&gt;\r\n&lt;form action=&lt;? echo $_SERVER [ 'PHP_SELF' ]; ?&gt; method =\"POST\"&gt;\r\n&lt;label for=name&gt;First name&lt;\/label&gt;&lt;br&gt;\r\n&lt;input type =\"text\" name =\"name\" id=name required&gt;\r\n&lt;br&gt;&lt;br&gt;\r\n&lt;label for=occu&gt;Occupation&lt;\/label&gt;&lt;br&gt;\r\n&lt;input type =\"text\" name =\"occu\" required&gt;&lt;br&gt;&lt;br&gt;\r\n&lt;input type=\"submit\" value=submit&gt;\r\n&lt;\/form&gt;\r\n&lt;?php\r\n}\r\n?&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<h3>1.5 $_GET<\/h3>\n<p>The $_GET superglobal associative array is used to access all the information sent using the GET method.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>index5.php<\/em><\/span><\/p>\n<pre class=\"brush:php;\">  \r\n\r\n&lt;!DOCTYPE html&gt; \r\n&lt;html lang=eng&gt;\r\n\t&lt;head&gt;\r\n\t&lt;style&gt;\r\n\thtml, body{\r\n\twidth:100%;\r\n\theight:100%;\r\n\tmargin:0%;\r\n\tfont-family:\"helvetica\",\"verdana\",\"calibri\", \"san serif\";\r\n\toverflow:hidden;\r\n\tpadding:0%;\r\n\tborder:0%;\r\n\t}\r\n\t \r\n\t&lt;\/style&gt;\r\n\t \t\t&lt;meta charset=\"utf-8\" \/&gt;\r\n\t\t&lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, target-densitydpi=device-dpi\"\/&gt;\r\n\t\r\n\t&lt;title&gt;HTML Form&lt;\/title&gt;\r\n\t\r\n\t&lt;\/head&gt;\r\n&lt;body&gt;\r\n\r\n&lt;?php\r\necho \t$_GET [ \"name\" ];\r\n?&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p>Assuming the user entered http:\/\/example.com\/?name=john.\u00a0The above example will output john<\/p>\n<h3>1.6 $_FILES<\/h3>\n<p>This superglobal variable holds items supplied to the script through HTTP POST.<\/p>\n<h3>1.7 $_ENV<\/h3>\n<p>This superglobal variable is an associative array of variables passed to the current script via the environment method.<\/p>\n<h3>1.8 $_COOKIE<\/h3>\n<p>This is a super global variable which\u00a0is used to manipulate cookie data.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>index6.php<\/em><\/span><\/p>\n<pre class=\"brush:php;\">&lt;!DOCTYPE html&gt; \r\n&lt;html lang=eng&gt;\r\n\t&lt;head&gt;\r\n\t&lt;style&gt;\r\n\thtml, body{\r\n\twidth:100%;\r\n\theight:100%;\r\n\tmargin:0%;\r\n\tfont-family:\"helvetica\",\"verdana\",\"calibri\", \"san serif\";\r\n\toverflow:hidden;\r\n\tpadding:0%;\r\n\tborder:0%;\r\n\t}\r\n\t \r\n\t&lt;\/style&gt;\r\n\t \t\t&lt;meta charset=\"utf-8\" \/&gt;\r\n\t\t&lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, target-densitydpi=device-dpi\"\/&gt;\r\n\t\r\n\t&lt;title&gt;superglobal example&lt;\/title&gt;\r\n\t\r\n\t&lt;\/head&gt;\r\n&lt;body&gt;\r\n\r\n&lt;?php\r\nif(isset($_COOKIE[\"name\"]))\r\necho \t$_COOKIE[ \"name\" ];\r\nelse\r\necho \"This cookie is not set\";\r\n?&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p>This checks if <code>$_COOKIE[\"name\"]<\/code> is set, if it is set print out it&#8217;s value else print out an error message.<\/p>\n<h3>1.8 $_SESSION<\/h3>\n<p><code>$_SESSION <\/code> is a superglobal which holds session variable.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>index7.php<\/em><\/span><\/p>\n<pre class=\"brush:php;\">&lt;?php\r\nsession_start ();\r\n\/* this signifies session has started if you don't write this line, you can't can't use $_Session global variable*\/\r\n$_SESSION [\"name\"]=\"john\";\r\n\/\/prints out the session variable\r\nfunction post(){\r\necho $_SESSION[\"name\"].\"&lt;br&gt;\";\r\n}\r\n\/\/update SESSION variable\r\nfunction change($d){\r\n$_SESSION [ \"name\" ]= $d;\r\n}\r\n?&gt;\r\n&lt;!DOCTYPE html&gt; \r\n&lt;html lang=eng&gt;\r\n\t&lt;head&gt;\r\n\t&lt;style&gt;\r\n\thtml, body{\r\n\twidth:100%;\r\n\theight:100%;\r\n\tmargin:0%;\r\n\tfont-family:\"helvetica\",\"verdana\",\"calibri\", \"san serif\";\r\n\toverflow:hidden;\r\n\tpadding:0%;\r\n\tborder:0%;\r\n\t}\r\n\t&lt;\/style&gt;\r\n\t \t\t&lt;meta charset=\"utf-8\" \/&gt;\r\n\t\t&lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, target-densitydpi=device-dpi\"\/&gt;\r\n\t&lt;title&gt;superglobal example&lt;\/title&gt;\r\n\t&lt;\/head&gt;\r\n&lt;body&gt;\r\n&lt;?php\r\npost();\/\/print out session variable\r\nchange(\"mark\");\/\/ update session variable\r\npost();\/\/print out session variable\r\n?&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<h2>2. Summary<\/h2>\n<p>In this example we learnt about PHP global variables. We learnt about <code>$GLOBALS<\/code>, <code>$_SERVER<\/code>, <code>$_REQUEST<\/code>,<code> $_POST<\/code>,<code> $_GET<\/code>,<code> $_FILES<\/code>, <code>$_ENV<\/code>, <code>$_COOKIE<span style=\"font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;\">\u00a0and<\/span><\/code><code>\u00a0$_SESSION<\/code><\/p>\n<h2>3. Download the source code<\/h2>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <strong><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/09\/phpglobalvariableexample.zip\">phpglobalvariableexample<\/a><br \/>\n<\/strong><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this example we will learn about PHP global variables, what they are and how to use them.\u00a0Variables are an integral part of any programming language. They are used to hold information about the programming context. Depending on where the variable is declared, it may be visible or invisible in other parts of the script(the &hellip;<\/p>\n","protected":false},"author":164,"featured_media":930,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-14683","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>PHP Global Variables Example - Web Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"In this example we will learn about PHP global variables, what they are and how to use them.\u00a0Variables are an integral part of any programming language.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.webcodegeeks.com\/php\/php-global-variables-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PHP Global Variables Example - Web Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"In this example we will learn about PHP global variables, what they are and how to use them.\u00a0Variables are an integral part of any programming language.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webcodegeeks.com\/php\/php-global-variables-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webcodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2016-09-21T12:43:35+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-01-09T08:27:54+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Olayemi Odunayo\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Olayemi Odunayo\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-global-variables-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-global-variables-example\/\"},\"author\":{\"name\":\"Olayemi Odunayo\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/417918d9b5811210265e8590509718b8\"},\"headline\":\"PHP Global Variables Example\",\"datePublished\":\"2016-09-21T12:43:35+00:00\",\"dateModified\":\"2018-01-09T08:27:54+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-global-variables-example\/\"},\"wordCount\":576,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-global-variables-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg\",\"articleSection\":[\"PHP\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.webcodegeeks.com\/php\/php-global-variables-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-global-variables-example\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/php\/php-global-variables-example\/\",\"name\":\"PHP Global Variables Example - Web Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-global-variables-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-global-variables-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg\",\"datePublished\":\"2016-09-21T12:43:35+00:00\",\"dateModified\":\"2018-01-09T08:27:54+00:00\",\"description\":\"In this example we will learn about PHP global variables, what they are and how to use them.\u00a0Variables are an integral part of any programming language.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-global-variables-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webcodegeeks.com\/php\/php-global-variables-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-global-variables-example\/#primaryimage\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-global-variables-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.webcodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PHP\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/php\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"PHP Global Variables Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"name\":\"Web Code Geeks\",\"description\":\"Web Developers Resource Center\",\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.webcodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webcodegeeks\",\"https:\/\/x.com\/webcodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/417918d9b5811210265e8590509718b8\",\"name\":\"Olayemi Odunayo\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/016b2a353262962fceecf5c274161cd9ef60fdf1593ec95e71d37f5fd9b444f6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/016b2a353262962fceecf5c274161cd9ef60fdf1593ec95e71d37f5fd9b444f6?s=96&d=mm&r=g\",\"caption\":\"Olayemi Odunayo\"},\"description\":\"I am a programmer and web developer, who has experience in developing websites and writing desktop and mobile applications. I have worked with both schematic and schemaless databases. I am also familiar with third party API and working with cloud servers. I do programming on the client side with Java, JavaScript, html, Ajax and CSS while I use PHP for server side programming.\",\"sameAs\":[\"https:\/\/www.webcodegeeks.com\/\"],\"url\":\"https:\/\/www.webcodegeeks.com\/author\/olayemi-odunayo\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PHP Global Variables Example - Web Code Geeks - 2026","description":"In this example we will learn about PHP global variables, what they are and how to use them.\u00a0Variables are an integral part of any programming language.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.webcodegeeks.com\/php\/php-global-variables-example\/","og_locale":"en_US","og_type":"article","og_title":"PHP Global Variables Example - Web Code Geeks - 2026","og_description":"In this example we will learn about PHP global variables, what they are and how to use them.\u00a0Variables are an integral part of any programming language.","og_url":"https:\/\/www.webcodegeeks.com\/php\/php-global-variables-example\/","og_site_name":"Web Code Geeks","article_publisher":"https:\/\/www.facebook.com\/webcodegeeks","article_published_time":"2016-09-21T12:43:35+00:00","article_modified_time":"2018-01-09T08:27:54+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg","type":"image\/jpeg"}],"author":"Olayemi Odunayo","twitter_card":"summary_large_image","twitter_creator":"@webcodegeeks","twitter_site":"@webcodegeeks","twitter_misc":{"Written by":"Olayemi Odunayo","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webcodegeeks.com\/php\/php-global-variables-example\/#article","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/php\/php-global-variables-example\/"},"author":{"name":"Olayemi Odunayo","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/417918d9b5811210265e8590509718b8"},"headline":"PHP Global Variables Example","datePublished":"2016-09-21T12:43:35+00:00","dateModified":"2018-01-09T08:27:54+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/php\/php-global-variables-example\/"},"wordCount":576,"commentCount":0,"publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/php\/php-global-variables-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg","articleSection":["PHP"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webcodegeeks.com\/php\/php-global-variables-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webcodegeeks.com\/php\/php-global-variables-example\/","url":"https:\/\/www.webcodegeeks.com\/php\/php-global-variables-example\/","name":"PHP Global Variables Example - Web Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/php\/php-global-variables-example\/#primaryimage"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/php\/php-global-variables-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg","datePublished":"2016-09-21T12:43:35+00:00","dateModified":"2018-01-09T08:27:54+00:00","description":"In this example we will learn about PHP global variables, what they are and how to use them.\u00a0Variables are an integral part of any programming language.","breadcrumb":{"@id":"https:\/\/www.webcodegeeks.com\/php\/php-global-variables-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webcodegeeks.com\/php\/php-global-variables-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/php\/php-global-variables-example\/#primaryimage","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.webcodegeeks.com\/php\/php-global-variables-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webcodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"PHP","item":"https:\/\/www.webcodegeeks.com\/category\/php\/"},{"@type":"ListItem","position":3,"name":"PHP Global Variables Example"}]},{"@type":"WebSite","@id":"https:\/\/www.webcodegeeks.com\/#website","url":"https:\/\/www.webcodegeeks.com\/","name":"Web Code Geeks","description":"Web Developers Resource Center","publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webcodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.webcodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.webcodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webcodegeeks","https:\/\/x.com\/webcodegeeks"]},{"@type":"Person","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/417918d9b5811210265e8590509718b8","name":"Olayemi Odunayo","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/016b2a353262962fceecf5c274161cd9ef60fdf1593ec95e71d37f5fd9b444f6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/016b2a353262962fceecf5c274161cd9ef60fdf1593ec95e71d37f5fd9b444f6?s=96&d=mm&r=g","caption":"Olayemi Odunayo"},"description":"I am a programmer and web developer, who has experience in developing websites and writing desktop and mobile applications. I have worked with both schematic and schemaless databases. I am also familiar with third party API and working with cloud servers. I do programming on the client side with Java, JavaScript, html, Ajax and CSS while I use PHP for server side programming.","sameAs":["https:\/\/www.webcodegeeks.com\/"],"url":"https:\/\/www.webcodegeeks.com\/author\/olayemi-odunayo\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/14683","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/users\/164"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/comments?post=14683"}],"version-history":[{"count":0,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/14683\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media\/930"}],"wp:attachment":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media?parent=14683"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/categories?post=14683"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/tags?post=14683"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}