Configuring Servers and Databases with Chrome - The server-side response
(Page 2 of 5 )
PHP scripts result in text being returned to a browser in one of two ways:
- Any text not bracketed by the PHP directives
<?phpand?>is passed directly to the browser.
- PHP statements within the PHP tags send text to the browser through a function such asecho().
The parameters sent to a script from a browser’sGETrequest arrive as values in an associative array named$_GET. To assign a PHP variable (a token that begins with$) a parameter from aGETrequest, we would write:
$myValue = $_GET['keyString']
For now, our command processor script will presume only valid commands, and compare the command against our temporarily hardcoded strings to return atrueorfalseresponse to the client. We can use any text editor to create the doCommand.php file:
<?php
$cmd = trim($_GET['command']);
$uName = trim($_GET['un']);
$uPass = trim($_GET['pd']);
echo check_user($uName,$uPass);
function check_user($name,$pass) {
if (($name == 'XULuser') &&
($pass == 'XULpass'))
return 'retcode=true';
else return 'retcode=false';
}
?>
Save this file in the Apache document root directory.
The code illustrates assignment of theGETparameters to global variables. Thetrimfunction takes care of any leading or trailing spaces that may have been entered. The script then passes the username and password to a comparison function that returnstrueorfalse, which is echoed back to the client.
Repeating the same launch of ournewssearch chrome package will yield the same results with our client-only code, but we are now operating in client/server mode.
Next: When Things Go Wrong >>
More Web Standards Articles
More By O'Reilly Media
|
This article is excerpted from chapter four of Programming Firefox, written by Kenneth C. Feldt (O'Reilly, 2007; ISBN: 0596102437). Check it out today at your favorite bookstore. Buy this book now.
|
|