Prev | Current Page 438 | Next

W. Jason Gilmore

"Beginning PHP and MySQL: From Novice to Professional"

The difference lies in the script??™s additional duty of
reading the text file into an array, and then cycling through that array searching for a
match. This involves the use of several functions, including the following:
??? file(string filename): The file() function reads a file into an array, with each
element of the array consisting of a line in the file.
??? explode(string separator, string string [, int limit]): The explode()
function splits a string into a series of substrings, with each string boundary
determined by a specific separator.
??? md5(string str): The md5() function calculates an MD5 hash of a string, using
RSA Security Inc.??™s MD5 Message-Digest algorithm (http://www.rsa.com/).
?– Note Although they are similar in function, you should use explode() instead of split(), because
split() is a tad slower due to its invocation of PHP??™s regular expression parsing engine.
372 CHAPTER 14 ?–  AUTHENTICATING YOUR USERS
Listing 14-4 illustrates a PHP script that is capable of parsing authenticationFile.txt,
potentially matching a user??™s input to a login pair.
Listing 14-4. Authenticating a User Against a Flat File Login Repository
// Preset authentication status to false
$authorized = FALSE;
if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
// Read the authentication file into an array
$authFile = file("/usr/local/lib/php/site/authenticate.


Pages:
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450