I l @ ve RuBoard |
Predefined VariablesThere are two reasons you will want to understand the concept of predefined variables: 1) because they have their own uses in your programming; and, 2) so that you don't inadvertently create a variable with the same name . Predefined variables are a special type of variable that the Web server application (for example, Apache), the Web server operating system (Solaris or Windows NT), or the PHP module itself uses. The first two categories are also referred to as "environmental variables." There will be some inconsistencies among servers as to what predefined variables exist, so use your test.php script (discussed in Chapter 1) to see which are in use on your machine (Figure 2.1). Figure 2.1. Another great use of the test.php script is to check to see which environmental and PHP variables exist and what their settings are.
Examples of a server's environmental variables are: HOSTNAME (how the server refers to itself), and OSTYPE (what operating system the server is running). Examples of Apache's environmental variables are: DOCUMENT_ROOT, which indicates where the files are stored on the server; and HTTP_USER_AGENT, which details the browser and platform of the person viewing the page. The PHP_SELF variable is the most commonly used PHP variable and is equal to the name of the current page. In Figure 2.1, the PHP_SELF variable indicates that the page being viewed is test.php. Tip Although it's not likely, creating a variable within a page with the same name as an environmental variable will cause peculiar results, so being aware of the existing variable names ahead of time makes your debugging easier. As you can tell from the list of environmental variables produced by our test.php script (Figure 2.1), simply by not using all capital letters as a variable name, you minimize the chance of a conflict. |
I l @ ve RuBoard |