PHP automatically creates variables for all the data it
receives in an HTTP request. This can include GET data, POST data, cookie data,
and environment variables. The variables are either in PHP's global symbol table
or in one of a number of superglobal arrays, depending on the value of the
register_globals setting in your php.ini
file.
Note that the
'error' field is new for PHP 4.2.0 and
the values are:
0 no error, file was uploaded);
1 (the
uploaded file exceeds the
upload_max_filesize directive in
php.ini;
2 the uploaded file exceeds the
MAX_FILE_SIZE directive that was specified in the HTML form;
3 the actual number of bytes uploaded was less than the specified
upload file size; and
4.
However, having seen some of the possible values of HTTP_USER_AGENT in the last chapter, you can imagine that
there are hundreds of slightly different values. So it's time to learn some
basic pattern matching.
You'll use the preg_match() function to
perform this task. This function needs two arguments: what you're looking for,
and where you're looking:
This function will return a value of true or false, which you can
use in an if…else block to
do whatever you want. The goal of the first script is to determine if a Web
browser is Microsoft Internet Explorer, Netscape, or something else. This can be
a little tricky, but not because of PHP.
Within the value of HTTP_USER_AGENT,
Netscape always uses the string Mozilla to identify
itself. Unfortunately, the value of HTTP_USER_AGENT for
Microsoft Internet Explorer also uses Mozilla to show
that it's compatible. Luckily, it also uses the string MSIE, so you can search for that. If the value of HTTP_USER_AGENT doesn't contain either Mozilla or MSIE, chances are very
good that it's not one of those Web browsers.