"
Global" is a poor choice of word! It really means "share this variable in this function with the variable of the same name at the top level" but there isn't a simple, easy better word for that than "Global". If you bring in code within an include / require file, then any top level code's variables in there will also be in the space that will be shared by any global declarations within the functions.
Superglobals are variables like $PHP_SELF, $_REQUEST, and $_SERVER. They are so called because they're always available in any functions without you having to make a global declaration. However, once again they do not persist between pages in a session, with the singular exception of $_SESSION as described in the next paragraph.
(Super)global variables of this type do NOT persist between successive pages of a session - the (modern) way for a variable to persist in that way is to (a) have a session_start() call in your code and (b) save the value you want to retain in the $_SESSION superglobal.
The other way to retain information between pages in a session is to bounce the information required via the browser - either in the form of hidden fields, a URL rewrite, or a cookie. That's really how $_SESSION works, but it's hidden from the programmer at the low level, and the information bounced via the browser is a single value which equates to a file name or database row key which can in turn be used to pick up all the other saved (session) values on the server.
It has been suggested that rather more than just these variables can be stored between pages, as database connection sometimes appear to persist rather than be refreshed every time. This is rather different - PHP routines like mysql_pconnect will make a persistent connection which will be stored in a pool of open connections once a page is completed. Then the already existing connection can be reused by a subsequent page which may, or may not, be a part of the same session.
(written 2006-11-21 16:46:39)
Associated topics are indexed under
H105 - PHP - Functions [2488] A variable number of arguments in a PHP function - (2009-11-02)
[1784] Global - Tcl, PHP, Python - (2008-09-03)
[1380] Static variables in PHP - (2007-10-05)
[1357] Clean my plate, but keep my wine bottle. (PHP; Static) - (2007-09-18)
[1267] is there a lookup function in php? - (2007-07-15)
[1202] Returning multiple values from a function (Perl, PHP, Python) - (2007-05-24)
[1163] A better alternative to cutting and pasting code - (2007-04-26)
[1021] PHP - static declaration - (2007-01-04)
[866] A lazy programmer is a good programmer - (2006-09-15)
[775] Do not duplicate your code - (2006-06-23)
[421] Don't repeat code - use loops or functions - (2005-08-21)
[409] Functions and commands with dangerous names - (2005-08-11)
[340] Code and code maintainance efficiency - (2005-06-08)
[339] Passing information into and out of PHP functions - (2005-06-07)
[308] Call by name v call by value - (2005-05-11)
[223] There is a function in PHP to do that - (2005-02-21)
[96] Variable Scope - (2004-10-22)
H112 - PHP - Further Web Page and Network Handling [1549] http, https and ajp - comparison and choice - (2008-02-22)
[1518] Downloading data for use in Excel (from PHP / MySQL) - (2008-01-25)
[1515] Keeping staff up to date on hotel room status - (2008-01-22)
[1505] Script to present commonly used images - PHP - (2008-01-13)
[1496] PHP / Web 2 logging - (2008-01-06)
[1495] Single login and single threaded models - Java and PHP - (2008-01-04)
[1485] Copyright and theft of images, bandwidth and members. - (2007-12-26)
[1379] Simple page password protection - PHP - (2007-10-04)
[1355] .php or .html extension? Morally Static Pages - (2007-09-17)
[1210] PHP header() function - uses and new restrictions - (2007-05-30)
[1187] Updating a page strictly every minute (PHP, Perl) - (2007-05-14)
[1183] Improving searches - from OR to AND? - (2007-05-11)
[1114] PHP Image upload script - (2007-03-21)
[1009] Passing GET parameters through Apache mod_rewrite - (2006-12-27)
[904] Of course I'll tell you by email - (2006-10-25)
[847] Image maps for navigation - a straightforward example - (2006-08-28)
[789] Hot answers in PHP - (2006-07-02)
[767] Finding the language preference of a web site visitor - (2006-06-18)
[732] Where is a web site visitor browsing from - (2006-05-24)
[675] Adding PHP tags to an old cgi program - (2006-04-08)
[603] PHP - setting sort order with an associative array - (2006-02-13)
[565] Using PHP to output images, XML, Style sheets, etc - (2006-01-15)
[542] Morning image, afternoon image - (2005-12-26)
[537] Daily Image Santafied - (2005-12-22)
[484] Setting the file name for a downloaded document - (2005-11-03)
[451] Accessing a page via POST from within a PHP script - (2005-09-26)
[443] Server side scripting of styles to suit the browser - (2005-09-12)
[425] Caching an XML feed - (2005-08-26)
[410] Reading a news or blog feed (RSS) in your PHP page - (2005-08-12)
[376] What brings people to my web site? - (2005-07-13)
[372] Time calculation in PHP - (2005-07-08)
[356] Sudoku helper or sudoku cheat - (2005-06-23)
[345] Spotting a denial of service attack - (2005-06-12)
[314] What language is this written in? - (2005-05-17)
[220] When to use Frames - (2005-02-19)
H115 - Designing PHP-Based Solutions: Best Practice [2430] Not just a PHP program - a good web application - (2009-09-29)
[2221] Adding a newsfeed for your users to a multipage PHP application - (2009-06-06)
[2199] Improving the structure of your early PHP programs - (2009-05-25)
[1794] Refactoring - a PHP demo becomes a production page - (2008-09-12)
[1694] Defensive coding techniques in PHP? - (2008-07-02)
[1623] PHP Techniques - a workshop - (2008-04-26)
[1533] Short and sweet and sticky - PHP form input - (2008-02-06)
[1490] Software to record day to day events and keep an action list - (2007-12-31)
[1487] Efficient PHP applications - framework and example - (2007-12-28)
[1482] A story about benchmarking PHP - (2007-12-23)
[1391] Ordnance Survey Grid Reference to Latitude / Longitude - (2007-10-14)
[1390] Converting from postal address to latitude / longitude - (2007-10-13)
[1389] Controlling and labelling Google maps via PHP - (2007-10-13)
[1381] Using a MySQL database to control mod_rewrite via PHP - (2007-10-06)
[1323] Easy handling of errors in PHP - (2007-08-27)
[1321] Resetting session based tests in PHP - (2007-08-26)
[1194] Drawing hands on a clock face - PHP - (2007-05-19)
[1182] Painting a masterpiece in PHP - (2007-05-10)
[1181] Good Programming practise - where to initialise variables - (2007-05-09)
[1166] Back button - ensuring order are not submitted twice (PHP) - (2007-04-28)
[1052] Learning to write secure, maintainable PHP - (2007-01-25)
[1047] Maintainable code - some positive advice - (2007-01-21)
[945] Code quality counts - (2006-11-26)
[896] PHP - good coding practise and sticky radio buttons - (2006-10-17)
[839] Reporting on the 10 largest files or 10 top scores - (2006-08-20)
[572] Giving the researcher power over database analysis - (2006-01-22)
[563] Merging pictures using PHP and GD - (2006-01-13)
[426] Robust checking of data entered by users - (2005-08-27)
[394] A year on - should we offer certified PHP courses - (2005-07-28)
[261] Putting a form online - (2005-03-29)
[237] Crossfertilisation, PHP to Python - (2005-03-06)
[123] Short underground journeys and a PHP book - (2004-11-19)
Some other Articles
Winter at Well House Manor - Open HousesSwipe cards for hotel rooms - Security issuesBratton and Edington new town, WiltshireDisplay an image from a MySQL database in a web page via PHPGlobal, Superglobal, Session variables - scope and persistance in PHPAutumn leaves in Wiltshire - PotterneClustering, load balancing, mod_rewrite and mod_proxyCourse Joining package - updatedA tale of a wee wallBefore and After - Well House Manor