[ Team LiB ] |
![]() ![]() |
The $_SERVER ArrayThe $_SERVER array contains elements set by your script's context, usually the server. There is no guarantee that any or all of the common elements will be set in it. If you are running PHP as a server module, however, it is likely that you will find at least the elements summarized in Table 10.2. They can be very useful in providing additional information about the context of a user request. In Listing 10.1, we loop through the $_SERVER array, printing the results to the browser. Listing 10.1 Looping Through the $_SERVER Array1: <!DOCTYPE html PUBLIC 2: "-//W3C//DTD XHTML 1.0 Strict//EN" 3: "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 4: <html> 5: <head> 6: <title>Listing 10.1 Looping through the $_SERVER array</title> 7: </head> 8: <body> 9: <div> 10: <?php 11: foreach ( $_SERVER as $key=>$value ) { 12: print "\$_SERVER[\"$key\"] == $value<br/>"; 13: } 14: ?> 15: </div> 16: </body> 17: </html> We use a foreach loop to access the keys and values in $_SERVER, printing to the browser on line 12. If PHP is running as a server module, you should find the elements listed in Table 10.2 in the output. Note the PHP_SELF element in particular. We use it to point forms and links back at their enclosing scripts in examples throughout this book. |
[ Team LiB ] |
![]() ![]() |