AJAX - The Complete Reference

(avery) #1

Chapter 4: Data Formats 141


PART I


On the server side, the PHP first checks if the Content-Transfer-Encoding is set and
if it is, it then decodes the payload using the built-in base64_decode() function. This will
result in the data being converted into a standard form request format. Since it is too late for
the PHP environment to populate the super global arrays for $_POST and $_REQUEST, the
PHP function, parse_str() is used to convert x-www-form-urlencoded strings into an
associative array of name-value pairs.

$payloadString = $GLOBALS['HTTP_RAW_POST_DATA'];
$payloadArray = array();
if (strstr($headers["Content-Type"], "text/plain"))
{
if (isset($headers["Content-Transfer-Encoding"])
&& $headers["Content-Transfer-Encoding"] == "base64")
{
$payloadString = base64_decode($payloadString);
parse_str($payloadString, $payloadArray);
}
}

Given that an encoded format is used here, it is not a far leap to introduce a compressed
format. However, since this is more related to improving network performance, this
discussion will be presented in Chapter 6.
In conclusion, there really is no limit to how data can be formatted for interchange in an
Ajax application. Some formats may be a bit easier than others to implement. A few might be
a little terser than others, but given the relative size of request packets, this will provide
meager savings. An encoded format such as base64 might provide some value in visual
security in case someone is able to briefly inspect your data stream, but remember that isn’t a
complete approach to Ajax data security. In short, there seems to be little reason to move
Free download pdf