Security stems from a lot of various steps, taken at different levels of an application. The Defense in Depth principle calls for redundant safeguards. For instance, you have to filter input into your application (e.g. data coming from a user form) and to escape output (e.g. when you display this data on an HTML page).
This tutorial decribes how to use the PHP Security Server Formats extension for Dreamweaver to easily and quickly increase the level of security of your PHP pages by escaping or forcing the type of the output onto your pages.
Consider this simple form and PHP code (note the last line, which displays a recordset field: <?php echo $row_Recordset1['varcharField']; ?>):
<form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>"> <textarea name="textarea" id="textarea" cols="45" rows="5"></textarea> <input type="submit" name="button" id="button" value="Send" /> <input type="hidden" name="MM_insert" value="form1" /> </form> <p>This can be any type:<?php echo $row_Recordset1['varcharField']; ?></p>
We have added to the page an Insert record Dreamweaver server behavior and a recordset that retreives the value stored in the database:
<?php
[...]
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO security (varcharField) VALUES (%s)",
GetSQLValueString($_POST['textarea'], "text"));
mysql_select_db($database_rsSSF, $rsSSF);
$Result1 = mysql_query($insertSQL, $rsSSF) or die(mysql_error());
}
mysql_select_db($database_rsSSF, $rsSSF);
$query_Recordset1 = "SELECT * FROM security";
$Recordset1 = mysql_query($query_Recordset1, $rsSSF) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
Now, if the user simply enters this in the textarea field:
<script type="text/javascript">
alert("You've been hacked!");
</script>
The JavaScript code gets executed once the form is sent and the field value is output to the page (fig. 1). Here, we are just throwing an alert box, but this could be used to play a number of tricks on your pages.

Fig. 1 - Our form and the injection of JavaScript code onto the page (Code and Design views, in Live view).
Of course, user input should be filtered by the form logic, but as security comes from a series of steps, escaping data or forcing its type before displaying it onto the page is a supplementary step that will make it harder to hack your pages.
Now, lets apply the HTML Entities With Parameters PHP server behavior (Fig. 2). Select {Recordset1.varcharField} in Design view, and open the Bindings panel wide enough so that the Format column appears. The varcharField in the Recordset1 is now selected and we can click the little arrow in the Format column to reveal various server formats. Once the PHP Security Server Formats extension is installed, you can see a Security category, with several server formats. We click on the HTML Entities With Parameters one.

Fig. 2 - Inserting a PHP security server format in Dreamweaver.
Now, as we can see in Live Code, the HTML characters have been converted into their corresponding entities, which prevents JavaScript code from being executed.

Fig. 3 - Escaping output prevents the execution of JavaScript code.
The PHP Security Server Formats extension comes with a number of formats intended to make sure that the data you will output onto the page will be of the desired type:
<p>This will be an integer: <?php echo strval(intval($row_Recordset1['integerField'])); ?></p>
Fig. 4 shows the code inserted (in Code view), the value of the varcharField in the database (which is the same HTML + JavaScript code as above) and the result in Live View, which is neutralized by the Integer server format and becomes 0. This is not very pretty (for the hacker!) and the insertion of JavaScript code must be prevented up-front in the form server logic anyway, but at least, this data cannot do any harm. Keep in mind that your database could be hacked in another way. This is the illustration of the Defense in Depth principle.

fig. 4 - Neutralizing possible tainted content with PHP Security Server Format.
<p>This will be a floating point number: <?php echo strval(floatval($row_Recordset1['floatField'])); ?></p>
<p>This will convert all applicable characters to HTML entities: <?php echo htmlentities($row_Recordset1['varcharField'], ENT_QUOTES, 'UTF-8'); ?></p>
<p>This will convert all applicable characters to HTML entities and will insert HTML line breaks before all new lines: <?php echo nl2br(htmlentities($row_Recordset1['varcharField'], ENT_QUOTES, 'UTF-8')); ?></p>
<p>This will strip HTML and PHP tags from a string: <?php echo strip_tags($row_Recordset1['varcharField'], '<span>'); ?></p>
<p>This will strip HTML and PHP tags from a string and will insert HTML line breaks before all new lines: <?php echo nl2br(strip_tags($row_Recordset1['varcharField'], '<p><br>')); ?></p>
<p>This will hash a string with a salt of your choice: <?php echo md5("mySalt" . md5($row_Recordset1['varcharField'] . "mySalt")); ?></p>
A number of the security server formats above use several parameters that you can modify.

Fig. 5 - The dialog box to customize the HTML entities with parameters security server format.