9. It's time to add the business logic now. Start by creating config.php, with this code in it:
<?php
// defines database connection data
define('DB_HOST', 'localhost');
define('DB_USER', 'ajaxuser');
define('DB_PASSWORD', 'practical');
define('DB_DATABASE', '
?>
10. Now create the error handler code in a file named error_handler.php:
<?php
// set the user error handler method to be error_handler
set_error_handler('error_handler', E_ALL);
// error handler function
function error_handler($errNo, $errStr, $errFile, $errLine)
{
// clear any output that has already been generated
if(ob_get_length()) ob_clean();
// output the error message
$error_message = 'ERRNO: ' . $errNo . chr(10) .
'TEXT: ' . $errStr . chr(10) .
'LOCATION: ' . $errFile .
', line ' . $errLine;
echo $error_message;
// prevent processing any more PHP scripts
exit;
}
?>
11. The PHP script that handles the client's
<?php
// start PHP session
session_start();
// load error handling script and validation class
require_once ('error_handler.php');
require_once ('validate.class.php');
// Create new validator object
$validator = new Validate();
// read validation type (PHP or
$validationType = '';
if (isset($_GET['validationType']))
{
$validationType = $_GET['validationType'];
}
//
if ($validationType == 'php')
{
// PHP validation is performed by the ValidatePHP method, which returns
// the page the visitor should be redirected to (which is allok.php if
// all the data is valid, or back to index.php if not)
header("Location:" . $validator->ValidatePHP());
}
else
{
//
// are used to form an XML document that is sent back to the client
$response =
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' .
'<response>' .
'<result>' .
$validator->ValidateAJAX($_POST['inputValue'], $_POST['fieldID']) .
'</result>' .
'<fieldid>' .
$_POST['fieldID'] .
'</fieldid>' .
'</response>';
// generate the response
if(ob_get_length()) ob_clean();
header('Content-Type: text/xml');
echo $response;
}
?>
0 comments:
Post a Comment