\n\n";
+
+for ($i = 0; $i < count($posts); $i++) {
+
+ $stmt = "INSERT INTO fb_posts (user_id, subject, body, timestamp) VALUES ('" . $posts[$i]['user_id'] . "', '" . $posts[$i]['subject'] . "', '" . $posts[$i]['body'] . "', '" . $posts[$i]['timestamp'] . "')";
+
+ $result = mysql_query($stmt, $db);
+
+ echo "$stmt \n";
+
+}
+
+?>
\ No newline at end of file
diff --git a/chapter08/Chapter 08/flashblog files/retrieve_posts.php b/chapter08/Chapter 08/flashblog files/retrieve_posts.php
new file mode 100644
index 0000000..8e8596f
--- /dev/null
+++ b/chapter08/Chapter 08/flashblog files/retrieve_posts.php
@@ -0,0 +1,51 @@
+SQL query failed. Please try again.";
+ exit;
+
+}
+
+// Find the number of rows returned (i.e. the number of posts)
+$numRows = @mysql_num_rows($result);
+
+// Were there any rows?
+if ($numRows <= 0) {
+
+ // No rows were returned, there mustn't be any entries
+ echo "There are currently no entries in the database.";
+ exit;
+
+}
+
+// Open the XML document
+$XMLString = "";
+
+// Loop through each row and create the node with all the correct information
+for ($i = 0; $i < $numRows; $i++) {
+
+ $row = @mysql_fetch_array($result);
+
+ $XMLString .= "" . $row['first_name'] . "" . $row['last_name'] . "" . urlencode($row['subject']) . "" . urlencode($row['body']) . "";
+
+}
+
+// Finish the XML document
+$XMLString .= "";
+
+// Return the XML to Flash
+echo $XMLString;
+
+?>
\ No newline at end of file
diff --git a/chapter08/Chapter 08/flashblog files/setup_flashblog_db.php b/chapter08/Chapter 08/flashblog files/setup_flashblog_db.php
new file mode 100644
index 0000000..92572e1
--- /dev/null
+++ b/chapter08/Chapter 08/flashblog files/setup_flashblog_db.php
@@ -0,0 +1,72 @@
+
+
+// Define the details of the database
+$db_user = "root"; // username
+$db_password = ""; // password
+$db_name = "flashblog"; // database name
+$db_host = "localhost"; // host name
+
+// Connect to the mysql server, if an error occurs, return an error message and exit the script
+if(!$db=@mysql_connect($db_host, $db_user, $db_password)) {
+ exit("An error occured while connecting to the MySQL server. \n");
+}
+
+// Select the database, if an error occurs return an error message and exit the script
+if(!mysql_select_db($db_name, $db)) {
+ echo "Unable to select the database $db_name. \n I will attempt to create it.
\n\n";
+}
+
+// Create the database
+if (!$result=@mysql_query("CREATE DATABASE $db_name", $db)) {
+
+ exit("Unable to create database $db_name. \nError #" . mysql_errno($db) . ": " . mysql_error($db) . " \n");
+
+}
+
+echo "The database $db_name has been created. \n I will attempt to create the necessary tables.
\n\n";
+
+// Select the database, if an error occurs return an error message and exit the script
+if(!mysql_select_db($db_name, $db)) {
+ exit("Unable to select the database $db_name \n.");
+}
+
+echo "Selected database $db_name.
\n\n";
+
+// The SQL statement to create the fb_posts table
+$create_fbposts = "CREATE TABLE fb_posts (
+ id INT(4) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ user_id INT(4),
+ subject VARCHAR(200),
+ body TEXT,
+ timestamp VARCHAR(24))";
+
+if (!$result=@mysql_query($create_fbposts, $db)) {
+
+ echo "Unable to create the table fb_posts \nError #" . mysql_errno($db) . ": " . mysql_error($db) . " \nAttempting to create the next table
\n\n";
+
+} else {
+
+ echo "Successfully created the fb_posts table. \n";
+
+}
+
+$create_fbuser = "CREATE TABLE fb_user (
+ id int(4) NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ username varchar(12),
+ password varchar(12),
+ first_name varchar(12) NOT NULL default 'Firstname',
+ last_name varchar(26) NOT NULL default 'Lastname',
+ user_type varchar(13) NOT NULL default 'user',
+ session_id varchar(32) NOT NULL default '0')";
+
+if (!$result=@mysql_query($create_fbuser, $db)) {
+
+ echo "Unable to create the table fb_user \nError #" . mysql_errno($db) . ": " . mysql_error($db) . " \n";
+
+} else {
+
+ echo "Successfully created the fb_user table. \n";
+
+}
+
+?>
\ No newline at end of file
diff --git a/chapter08/Chapter 08/tutorial files/add_user_db.php b/chapter08/Chapter 08/tutorial files/add_user_db.php
new file mode 100644
index 0000000..350cc4b
--- /dev/null
+++ b/chapter08/Chapter 08/tutorial files/add_user_db.php
@@ -0,0 +1,27 @@
+
+
+Creating a user table
+
+
+
+
+
+
+
+
diff --git a/chapter08/Chapter 08/tutorial files/connecting_db.php b/chapter08/Chapter 08/tutorial files/connecting_db.php
new file mode 100644
index 0000000..711737d
--- /dev/null
+++ b/chapter08/Chapter 08/tutorial files/connecting_db.php
@@ -0,0 +1,30 @@
+
+
+
+
+ Creating a MySQL Database
+
+
+\n");
+
+if (!mysql_select_db($database, $mysql_connection)) {
+
+ echo "Failed to connect to database: $database. \n";
+ echo "Error information: " . mysql_errno($mysql_connection) . " " . mysql_error($mysql_connection) . " \n";
+
+ exit;
+}
+
+echo "Successfully connected to database: $database. \n";
+
+?>
+
+
+
diff --git a/chapter08/Chapter 08/tutorial files/create_table_db.php b/chapter08/Chapter 08/tutorial files/create_table_db.php
new file mode 100644
index 0000000..eaeab72
--- /dev/null
+++ b/chapter08/Chapter 08/tutorial files/create_table_db.php
@@ -0,0 +1,45 @@
+
+
+
+
+ Creating a MySQL Database
+
+
+
+\n");
+
+if (!mysql_select_db($database, $mysql_connection)) {
+
+ echo "Failed to connect to database: $database. \n";
+ echo "Error information: " . mysql_errno($mysql_connection) . " " . mysql_error($mysql_connection) . " \n";
+ exit;
+}
+
+$create_table = "CREATE TABLE users (
+ uid INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ username VARCHAR(16),
+ userpass VARCHAR(16),
+ realname VARCHAR(200),
+ email VARCHAR(200))";
+
+if (!$result=mysql_query($create_table, $mysql_connection)) {
+
+ echo "An error occured while creating the users table. \n";
+ echo "Error information: " . mysql_errno($mysql_connection) . " " .
+ mysql_error($mysql_connection) . " \n";
+ exit;
+}
+
+echo "The users table on $database has successfully been created. \n";
+
+?>
+
+
+
diff --git a/chapter08/Chapter 08/tutorial files/creating_db.php b/chapter08/Chapter 08/tutorial files/creating_db.php
new file mode 100644
index 0000000..42da032
--- /dev/null
+++ b/chapter08/Chapter 08/tutorial files/creating_db.php
@@ -0,0 +1,32 @@
+
+
+
+
+Creating a MySQL Database
+
+
+
+\n");
+
+ if (!mysql_create_db($database, $mysql_connection)) {
+
+ echo "Failed to create the new database $database. \n";
+ echo "Error #" . mysql_errno($mysql_connection) . ": " . mysql_error($mysql_connection);
+
+} else {
+
+ echo "Successfully created the database $database. \n";
+
+}
+
+?>
+
+
+
diff --git a/chapter08/Chapter 08/tutorial files/db_details.php b/chapter08/Chapter 08/tutorial files/db_details.php
new file mode 100644
index 0000000..4e8da09
--- /dev/null
+++ b/chapter08/Chapter 08/tutorial files/db_details.php
@@ -0,0 +1,8 @@
+
diff --git a/chapter08/Chapter 08/tutorial files/login.fla b/chapter08/Chapter 08/tutorial files/login.fla
new file mode 100644
index 0000000..6c09ebf
Binary files /dev/null and b/chapter08/Chapter 08/tutorial files/login.fla differ
diff --git a/chapter08/Chapter 08/tutorial files/login.html b/chapter08/Chapter 08/tutorial files/login.html
new file mode 100644
index 0000000..efb25fc
--- /dev/null
+++ b/chapter08/Chapter 08/tutorial files/login.html
@@ -0,0 +1,16 @@
+
+
+
+login
+
+
+
+
+
+
+
diff --git a/chapter08/Chapter 08/tutorial files/login.php b/chapter08/Chapter 08/tutorial files/login.php
new file mode 100644
index 0000000..9958781
--- /dev/null
+++ b/chapter08/Chapter 08/tutorial files/login.php
@@ -0,0 +1,99 @@
+
+
+ini_set("always_populate_raw_post_data", true);
+include("../includes/db_details.php");
+
+$currentTag = "";
+$user_username = "";
+$usernameValue = "";
+$user_password = "";
+$passwordValue = "";
+
+// The handler for the element opening tags
+function startElementHandler($parser, $name, $attr) {
+
+ global $currentTag, $user_username, $user_password;
+
+ $currentTag = $name;
+
+ if (strcmp($name, "LOGIN") == 0) {
+
+ $user_username = $attr["USERNAME"];
+ $user_password = $attr["PASSWORD"];
+
+ }
+
+}
+
+function endElementHandler() {
+
+ // do nothing
+
+}
+
+// Create the XML parser
+$parser = xml_parser_create();
+
+// Register the start and end element handlers
+xml_set_element_handler($parser, "startElementHandler", "endElementHandler");
+
+if (!xml_parse($parser, $HTTP_RAW_POST_DATA, true)) {
+
+ echo "";
+ exit();
+
+}
+
+// Ok, finished parsing the XML
+xml_parser_free($parser);
+
+$mysql_connection = mysql_connect($hostname, $username, $password);
+
+if (!$mysql_connection) {
+
+ exit("");
+
+} else {
+
+ if (!mysql_select_db($database, $mysql_connection)) {
+
+ $err = "An error occured while connecting to the database: " . mysql_errno($mysql_connection) . " " . mysql_error($mysql_connection);
+
+ exit("");
+
+ } else {
+
+ $add_user = "SELECT * FROM users";
+
+ $result = mysql_query($add_user, $mysql_connection);
+
+ if (!$result) {
+
+ $err = "An error occured while querying the database: " . mysql_errno($mysql_connection) . " " . mysql_error($mysql_connection);
+ exit("");
+
+ } else {
+
+ $numRows = mysql_num_rows($result);
+
+ for ($i = 0; $i < $numRows; $i++) {
+
+ $row = mysql_fetch_array($result);
+
+ if ($row["username"] == $user_username && $row["userpass"] == $user_password) {
+
+ exit("");
+
+ }
+
+ }
+
+ exit("");
+
+ }
+
+ }
+
+}
+
+?>
\ No newline at end of file
diff --git a/chapter08/Chapter 08/tutorial files/login.swf b/chapter08/Chapter 08/tutorial files/login.swf
new file mode 100644
index 0000000..e7b99c3
Binary files /dev/null and b/chapter08/Chapter 08/tutorial files/login.swf differ
diff --git a/chapter08/Chapter 08/tutorial files/save_user_db.php b/chapter08/Chapter 08/tutorial files/save_user_db.php
new file mode 100644
index 0000000..246e563
--- /dev/null
+++ b/chapter08/Chapter 08/tutorial files/save_user_db.php
@@ -0,0 +1,74 @@
+
+
+
+
+
+ Populating the database
+
+
+
+\n";
+
+} else if (!isset($pass_word) && $pass_word == "") {
+
+ $error = true;
+ $errorMsg .= "No password was supplied \n";
+
+} else if (!isset($real_name) && $real_name == "") {
+
+ $error = true;
+ $errorMsg .= "A real name was not supplied \n";
+
+} else if (!isset($email) && $email == "") {
+
+ $error = true;
+ $errorMsg .= "An email address was not supplied \n";
+
+}
+
+if ($error == true) {
+
+ echo "An error has occurred: \n $errorMsg";
+ exit;
+
+}
+
+$mysql_connection = @mysql_connect($hostname, $username, $password)
+ or exit("Failed to connect to the MySQL server. \n");
+
+if (!mysql_select_db($database, $mysql_connection)) {
+
+ echo "Failed to connect to database: $database. \n";
+ echo "Error information: " . mysql_errno($mysql_connection) . " " .
+ mysql_error($mysql_connection) . " \n";
+ exit;
+}
+
+$add_user = "INSERT INTO users (username, userpass, realname, email)
+ VALUES ('$user_name', '$pass_word', '$real_name', '$email')";
+
+if (!$result=mysql_query($add_user, $mysql_connection)) {
+ echo "An error occurred while adding the user: $user_name. \n";
+ echo "Error information: " . mysql_errno($mysql_connection) . " " .
+ mysql_error($mysql_connection) . " \n";
+ exit;
+}
+
+echo "The user $user_name was successfully added to the database. \n";
+
+?>
+
+
+
diff --git a/chapter08/Chapter 08/tutorial files/view_users_db.php b/chapter08/Chapter 08/tutorial files/view_users_db.php
new file mode 100644
index 0000000..745053a
--- /dev/null
+++ b/chapter08/Chapter 08/tutorial files/view_users_db.php
@@ -0,0 +1,52 @@
+
+
+
+
+ Creating a MySQL Database
+
+
+
+\n");
+
+if (!mysql_select_db($database, $mysql_connection)) {
+
+ echo "Failed to connect to database: $database. \n";
+ echo "Error information: " . mysql_errno($mysql_connection) . " " .
+ mysql_error($mysql_connection) . " \n";
+ exit;
+
+}
+
+$add_user = "SELECT * FROM users";
+
+if (!$result = mysql_query($add_user, $mysql_connection)) {
+
+ echo "An error occurred while retrieving user information. \n";
+ echo "Error information: " . mysql_errno($mysql_connection) . " " .
+ mysql_error($mysql_connection) . " \n";
+ exit;
+
+}
+
+$numRows = mysql_num_rows($result);
+
+for ($i = 0; $i < $numRows; $i++) {
+
+ $row = mysql_fetch_array($result);
+ echo "username: " . $row["username"] . " (" . $row["realname"] . ") \n";
+ echo "email: " . $row["email"] . " \n";
+ echo "";
+
+}
+
+?>
+
+
+
diff --git a/chapter09.sit b/chapter09.sit
new file mode 100644
index 0000000..b3a4e78
Binary files /dev/null and b/chapter09.sit differ
diff --git a/chapter09/Chapter 09/flashblog files/FL08F2~1.FLA b/chapter09/Chapter 09/flashblog files/FL08F2~1.FLA
new file mode 100644
index 0000000..3657a6e
Binary files /dev/null and b/chapter09/Chapter 09/flashblog files/FL08F2~1.FLA differ
diff --git a/chapter09/Chapter 09/flashblog files/ch09_flashblog_final.fla b/chapter09/Chapter 09/flashblog files/ch09_flashblog_final.fla
new file mode 100644
index 0000000..0bb57f6
Binary files /dev/null and b/chapter09/Chapter 09/flashblog files/ch09_flashblog_final.fla differ
diff --git a/chapter09/Chapter 09/flashblog files/ch09_flashblog_start.fla b/chapter09/Chapter 09/flashblog files/ch09_flashblog_start.fla
new file mode 100644
index 0000000..981a0b7
Binary files /dev/null and b/chapter09/Chapter 09/flashblog files/ch09_flashblog_start.fla differ
diff --git a/chapter09/Chapter 09/flashblog files/ch09_markup_start.fla b/chapter09/Chapter 09/flashblog files/ch09_markup_start.fla
new file mode 100644
index 0000000..8319b94
Binary files /dev/null and b/chapter09/Chapter 09/flashblog files/ch09_markup_start.fla differ
diff --git a/chapter09/Chapter 09/flashblog files/flashblog_ci_finish.fla b/chapter09/Chapter 09/flashblog files/flashblog_ci_finish.fla
new file mode 100644
index 0000000..27798c3
Binary files /dev/null and b/chapter09/Chapter 09/flashblog files/flashblog_ci_finish.fla differ
diff --git a/chapter09/Chapter 09/flashblog files/flashblog_ci_start.fla b/chapter09/Chapter 09/flashblog files/flashblog_ci_start.fla
new file mode 100644
index 0000000..fb0c13c
Binary files /dev/null and b/chapter09/Chapter 09/flashblog files/flashblog_ci_start.fla differ
diff --git a/chapter09/Chapter 09/flashblog files/flashblog_hk_start.fla b/chapter09/Chapter 09/flashblog files/flashblog_hk_start.fla
new file mode 100644
index 0000000..bf23de3
Binary files /dev/null and b/chapter09/Chapter 09/flashblog files/flashblog_hk_start.fla differ
diff --git a/chapter09/Chapter 09/flashblog files/flashblog_hka_start.fla b/chapter09/Chapter 09/flashblog files/flashblog_hka_start.fla
new file mode 100644
index 0000000..722e496
Binary files /dev/null and b/chapter09/Chapter 09/flashblog files/flashblog_hka_start.fla differ
diff --git a/chapter09/Chapter 09/flashblog files/flashblog_mdm_start.fla b/chapter09/Chapter 09/flashblog files/flashblog_mdm_start.fla
new file mode 100644
index 0000000..3e4f0a3
Binary files /dev/null and b/chapter09/Chapter 09/flashblog files/flashblog_mdm_start.fla differ
diff --git a/chapter09/Chapter 09/flashblog files/flashblog_pi_start.fla b/chapter09/Chapter 09/flashblog files/flashblog_pi_start.fla
new file mode 100644
index 0000000..24b4cc1
Binary files /dev/null and b/chapter09/Chapter 09/flashblog files/flashblog_pi_start.fla differ
diff --git a/chapter09/Chapter 09/flashblog files/markup.fla b/chapter09/Chapter 09/flashblog files/markup.fla
new file mode 100644
index 0000000..a60ace3
Binary files /dev/null and b/chapter09/Chapter 09/flashblog files/markup.fla differ
diff --git a/chapter09/Chapter 09/flashblog files/markup.swf b/chapter09/Chapter 09/flashblog files/markup.swf
new file mode 100644
index 0000000..896b4fb
Binary files /dev/null and b/chapter09/Chapter 09/flashblog files/markup.swf differ
diff --git a/chapter09/Chapter 09/flashblog files/markup2_start.fla b/chapter09/Chapter 09/flashblog files/markup2_start.fla
new file mode 100644
index 0000000..807a1c6
Binary files /dev/null and b/chapter09/Chapter 09/flashblog files/markup2_start.fla differ
diff --git a/chapter09/Chapter 09/flashblog files/markup_finish.fla b/chapter09/Chapter 09/flashblog files/markup_finish.fla
new file mode 100644
index 0000000..9ab14ec
Binary files /dev/null and b/chapter09/Chapter 09/flashblog files/markup_finish.fla differ
diff --git a/chapter09/Chapter 09/flashblog files/markup_mdm_start.fla b/chapter09/Chapter 09/flashblog files/markup_mdm_start.fla
new file mode 100644
index 0000000..c9dd9c2
Binary files /dev/null and b/chapter09/Chapter 09/flashblog files/markup_mdm_start.fla differ
diff --git a/chapter09/Chapter 09/flashblog files/save_config.php b/chapter09/Chapter 09/flashblog files/save_config.php
new file mode 100644
index 0000000..f3f676d
--- /dev/null
+++ b/chapter09/Chapter 09/flashblog files/save_config.php
@@ -0,0 +1,166 @@
+
+
+ini_set("always_populate_raw_post_data", true);
+
+// Include the database details, and make a connection
+include("../../fb_includes/database.php");
+
+// Include the checkLogin function
+include("functions.php");
+
+$currentTag = "";
+$username = "";
+$usernameValue = "";
+$blogLimit = "";
+$blogLimitValue = "";
+$templatePath = "";
+$templatePathValue = "";
+$templateFilename = "";
+$templateFilenameValue = "";
+$sessionID = "";
+$sessionIDValue = "";
+
+// The handler for the element opening tags
+function startElementHandler($parser, $name, $attr) {
+
+ global $currentTag;
+
+ $currentTag = $name;
+
+}
+
+// The handler for the element closing tags
+function endElementHandler($parser, $name) {
+
+ global $username, $usernameValue, $blogLimit, $blogLimitValue, $templatePath, $templatePathValue, $templateFilename, $templateFilenameValue, $sessionID, $sessionIDValue;
+
+ if (strcmp($name, "USERNAME") == 0) {
+
+ $username = $usernameValue;
+ $usernameValue = "";
+
+ } else if (strcmp($name, "BLOGLIMIT") == 0) {
+
+ $blogLimit = $blogLimitValue;
+ $blogLimitValue = "";
+
+ } else if (strcmp($name, "SESSION_ID") == 0) {
+
+ $sessionID = $sessionIDValue;
+ $sessionIDValue = "";
+
+ } else if (strcmp($name, "TEMPLATEPATH") == 0) {
+
+ $templatePath = $templatePathValue;
+ $templatePathValue = "";
+
+ } else if (strcmp($name, "TEMPLATEFILENAME") == 0) {
+
+ $templateFilename = $templateFilenameValue;
+ $templateFilenameValue = "";
+
+ }
+
+}
+
+// The handler for character data
+function cdataHandler($parser, $data) {
+
+ global $currentTag, $usernameValue, $blogLimitValue, $templatePathValue, $templateFilenameValue, $sessionIDValue;
+
+ if (strcmp($currentTag, "USERNAME") == 0) {
+
+ $usernameValue .= $data;
+
+ } else if (strcmp($currentTag, "BLOGLIMIT") == 0) {
+
+ $blogLimitValue .= $data;
+
+ } else if (strcmp($currentTag, "SESSION_ID") == 0) {
+
+ $sessionIDValue .= $data;
+
+ } else if (strcmp($currentTag, "TEMPLATEPATH") == 0) {
+
+ $templatePathValue .= $data;
+
+ } else if (strcmp($currentTag, "TEMPLATEFILENAME") == 0) {
+
+ $templateFilenameValue .= $data;
+
+ }
+
+}
+
+// Create the XML parser
+$parser = xml_parser_create();
+
+// Register the start and end element handlers
+xml_set_element_handler($parser, "startElementHandler", "endElementHandler");
+
+// Register the character data parser
+xml_set_character_data_handler($parser, "cdataHandler");
+
+if (!xml_parse($parser, $HTTP_RAW_POST_DATA, true)) {
+
+ $str = sprintf("XML error %d %d", xml_get_current_line_number($parser), xml_get_current_column_number($parser));
+
+ echo "false$str";
+ exit;
+
+}
+
+// Ok, finished parsing the XML
+xml_parser_free($parser);
+
+if (!isset($blogLimit) || $blogLimit == "") {
+
+ echo "falseXML packet failed, the blog limit was null.";
+ exit;
+
+} else if (!isset($sessionID) || $sessionID == "") {
+
+ echo "falseXML packet failed, there was no session id. Are you logged in?";
+ exit;
+
+} else if (!isset($templatePath) || $templatePath == "") {
+
+ echo "falseXML packet failed, the template path was undefined.";
+ exit;
+
+} else if (!isset($templateFilename) || $templateFilename == "") {
+
+ echo "falseXML packet failed, the template filename was undefined.";
+ exit;
+
+}
+
+// Check to see if the user is logged in
+if (!checkLogin($username, $sessionID)) {
+
+ echo "falseYou are not logged in.";
+ exit;
+
+}
+
+// Write the information to config.xml
+$content = "$blogLimit" . urldecode($templatePath) . "" . urldecode($templateFilename) . "";
+
+$path = "/www/s/smebberson/htdocs/flashblog/XML";
+$filename = "/config.xml";
+
+$fp = @fopen($path . $filename, "w");
+$write = @fwrite($fp, $content);
+
+if ($write == -1) {
+
+ echo "falseFailed while writing config.xml.";
+ exit;
+
+} else {
+
+ echo "trueThe configuration file was successfully updated.";
+
+}
+
+?>
\ No newline at end of file
diff --git a/chapter09/Chapter 09/flashblog files/save_post.php b/chapter09/Chapter 09/flashblog files/save_post.php
new file mode 100644
index 0000000..01256cf
--- /dev/null
+++ b/chapter09/Chapter 09/flashblog files/save_post.php
@@ -0,0 +1,213 @@
+false$str";
+ exit;
+
+}
+
+// Ok, finished parsing the POST XML
+xml_parser_free($parser);
+
+// Now load and parse the config.xml file
+$configParser = xml_parser_create();
+xml_set_element_handler($configParser, "startElementHandler", "endElementHandler");
+xml_set_character_data_handler($configParser, "cdataHandler");
+
+if (!$fp = @fopen("XML/config.xml", "r")) {
+
+ echo "falseFailed to open the configuration file.";
+ exit;
+
+}
+
+while ($data = fread($fp, 4096)) {
+
+ if (!xml_parse($configParser, $data, feof($fp))) {
+
+ $err = "There was an error in the XML in line " . xml_get_current_line_number($configParser) . " at position " . xml_get_current_column_number($configParser);
+
+ echo "false$err";
+ exit;
+
+ }
+}
+
+if (!isset($username) || $username == "") {
+
+ echo "falseThe user is not logged in.";
+ exit;
+
+} else if (!isset($time) || $time == "") {
+
+ echo "falseThe time was missing.";
+ exit;
+
+} else if (!isset($subject) || $subject == "") {
+
+ echo "falseThe subject was missing.";
+ exit;
+
+} else if (!isset($body) || $body == "") {
+
+ echo "falseThe body was missing.";
+ exit;
+
+} else if (!isset($blogLimit) || $blogLimit == "") {
+
+ echo "falseThere was an error in the configuration directives.";
+ exit;
+
+}
+
+$stmt = "INSERT INTO fb_posts (user_id, subject, body, timestamp) VALUES(1, '" . urldecode($subject) . "', '" . urldecode($body) . "', '$time')";
+
+$result = @mysql_query($stmt, $db);
+
+if ($result == 0) {
+
+ $str = echo "Error #" . mysql_errno($db) . ": " . mysql_error($db);
+ echo "falseDatabase update failed: " . $str . "";
+ exit;
+
+}
+
+$stmt = "SELECT id FROM fb_posts ORDER BY id DESC LIMIT $blogLimit";
+$result = @mysql_query($stmt, $db);
+
+if ($result == 0) {
+
+ $str = echo "Error #" . mysql_errno($db) . ": " . mysql_error($db);
+ echo "falseEntry was added, but the database failed while deleting old posts.";
+ exit;
+
+}
+
+$numRows = @mysql_num_rows($result);
+
+for ($i = 0; $i < $numRows; $i++) {
+
+ $row = @mysql_fetch_array($result);
+ $lastID = $row['id'];
+
+}
+
+$stmt = "DELETE FROM fb_posts WHERE id < $lastID";
+$result = @mysql_query($stmt, $db);
+
+if ($result == 0) {
+
+ echo "falseEntry was added, but the database failed while deleting old posts.";
+ exit;
+
+}
+
+echo "trueYour post was saved to the database.";
+
+
+?>
\ No newline at end of file
diff --git a/chapter09/Chapter 09/graphics/Thumbs.db b/chapter09/Chapter 09/graphics/Thumbs.db
new file mode 100644
index 0000000..39992c8
Binary files /dev/null and b/chapter09/Chapter 09/graphics/Thumbs.db differ
diff --git a/chapter09/Chapter 09/graphics/bttn.png b/chapter09/Chapter 09/graphics/bttn.png
new file mode 100644
index 0000000..2eba713
Binary files /dev/null and b/chapter09/Chapter 09/graphics/bttn.png differ
diff --git a/chapter09/Chapter 09/graphics/config_title.png b/chapter09/Chapter 09/graphics/config_title.png
new file mode 100644
index 0000000..c2bda72
Binary files /dev/null and b/chapter09/Chapter 09/graphics/config_title.png differ
diff --git a/chapter09/Chapter 09/graphics/footer.png b/chapter09/Chapter 09/graphics/footer.png
new file mode 100644
index 0000000..bdd4bc2
Binary files /dev/null and b/chapter09/Chapter 09/graphics/footer.png differ
diff --git a/chapter09/Chapter 09/graphics/header.png b/chapter09/Chapter 09/graphics/header.png
new file mode 100644
index 0000000..3edba7b
Binary files /dev/null and b/chapter09/Chapter 09/graphics/header.png differ
diff --git a/chapter09/Chapter 09/graphics/main_menu_title.png b/chapter09/Chapter 09/graphics/main_menu_title.png
new file mode 100644
index 0000000..3786a5d
Binary files /dev/null and b/chapter09/Chapter 09/graphics/main_menu_title.png differ
diff --git a/chapter09/Chapter 09/graphics/nav_bar.png b/chapter09/Chapter 09/graphics/nav_bar.png
new file mode 100644
index 0000000..79748e7
Binary files /dev/null and b/chapter09/Chapter 09/graphics/nav_bar.png differ
diff --git a/chapter09/Chapter 09/graphics/new_post_title.png b/chapter09/Chapter 09/graphics/new_post_title.png
new file mode 100644
index 0000000..bd79289
Binary files /dev/null and b/chapter09/Chapter 09/graphics/new_post_title.png differ
diff --git a/chapter09/Chapter 09/graphics/read_posts_title.png b/chapter09/Chapter 09/graphics/read_posts_title.png
new file mode 100644
index 0000000..e186e73
Binary files /dev/null and b/chapter09/Chapter 09/graphics/read_posts_title.png differ
diff --git a/chapter09/Chapter 09/graphics/sm.bmp b/chapter09/Chapter 09/graphics/sm.bmp
new file mode 100644
index 0000000..dbaef09
Binary files /dev/null and b/chapter09/Chapter 09/graphics/sm.bmp differ
diff --git a/chapter09/Chapter 09/graphics/square_bttn.png b/chapter09/Chapter 09/graphics/square_bttn.png
new file mode 100644
index 0000000..46541bb
Binary files /dev/null and b/chapter09/Chapter 09/graphics/square_bttn.png differ
diff --git a/chapter09/Chapter 09/tutorial files/PixelogicComponent.mxp b/chapter09/Chapter 09/tutorial files/PixelogicComponent.mxp
new file mode 100644
index 0000000..31b4f85
Binary files /dev/null and b/chapter09/Chapter 09/tutorial files/PixelogicComponent.mxp differ
diff --git a/chapter09/Chapter 09/tutorial files/access.php b/chapter09/Chapter 09/tutorial files/access.php
new file mode 100644
index 0000000..55a7973
--- /dev/null
+++ b/chapter09/Chapter 09/tutorial files/access.php
@@ -0,0 +1,25 @@
+
+
+ PHP Access logger
+
+
+ \n";
+
+ if (!$fp = fopen("access.log", "a")) {
+ exit("Failed to open access.log. \n");
+ }
+
+ if (!fwrite($fp, $str)) {
+ exit("Failed to write to file. \n");
+ }
+
+ fclose($fp);
+ echo "Accessed logged. \n";
+
+
+ ?>
+
+
+
diff --git a/chapter09/Chapter 09/tutorial files/messageBox_API.fla b/chapter09/Chapter 09/tutorial files/messageBox_API.fla
new file mode 100644
index 0000000..f2bb898
Binary files /dev/null and b/chapter09/Chapter 09/tutorial files/messageBox_API.fla differ
diff --git a/chapter09/Chapter 09/tutorial files/messageBox_parameters.fla b/chapter09/Chapter 09/tutorial files/messageBox_parameters.fla
new file mode 100644
index 0000000..d0faf19
Binary files /dev/null and b/chapter09/Chapter 09/tutorial files/messageBox_parameters.fla differ
diff --git a/chapter09/Chapter 09/tutorial files/progressBarPlus_finish.fla b/chapter09/Chapter 09/tutorial files/progressBarPlus_finish.fla
new file mode 100644
index 0000000..e4d3da2
Binary files /dev/null and b/chapter09/Chapter 09/tutorial files/progressBarPlus_finish.fla differ
diff --git a/chapter09/Chapter 09/tutorial files/progressBarPlus_start.fla b/chapter09/Chapter 09/tutorial files/progressBarPlus_start.fla
new file mode 100644
index 0000000..f640cb6
Binary files /dev/null and b/chapter09/Chapter 09/tutorial files/progressBarPlus_start.fla differ
diff --git a/chapter09/Chapter 09/tutorial files/viewer.php b/chapter09/Chapter 09/tutorial files/viewer.php
new file mode 100644
index 0000000..12f436d
--- /dev/null
+++ b/chapter09/Chapter 09/tutorial files/viewer.php
@@ -0,0 +1,18 @@
+
+
+ PHP Access Log Reader
+
+
+
+ \n");
+ }
+
+ fpassthru($fp);
+
+ ?>
+
+
+
diff --git a/chapter10/Chapter 10/Graphics/Thumbs.db b/chapter10/Chapter 10/Graphics/Thumbs.db
new file mode 100644
index 0000000..7bc9e6d
Binary files /dev/null and b/chapter10/Chapter 10/Graphics/Thumbs.db differ
diff --git a/chapter10/Chapter 10/Graphics/login_title.png b/chapter10/Chapter 10/Graphics/login_title.png
new file mode 100644
index 0000000..f66827a
Binary files /dev/null and b/chapter10/Chapter 10/Graphics/login_title.png differ
diff --git a/chapter10/Chapter 10/Graphics/logout_title.png b/chapter10/Chapter 10/Graphics/logout_title.png
new file mode 100644
index 0000000..20e39d6
Binary files /dev/null and b/chapter10/Chapter 10/Graphics/logout_title.png differ
diff --git a/chapter10/Chapter 10/flashblog files/check_login.php b/chapter10/Chapter 10/flashblog files/check_login.php
new file mode 100644
index 0000000..3eafeff
--- /dev/null
+++ b/chapter10/Chapter 10/flashblog files/check_login.php
@@ -0,0 +1,132 @@
+
+ini_set("always_populate_raw_post_data", true);
+
+// Include the database details, and make a connection
+include("../../fb_includes/database.php");
+
+$currentTag = "";
+$username = "";
+$usernameValue = "";
+$sessionID = "";
+$sessionIDValue = "";
+$level = "";
+$levelValue = "";
+
+// The handler for the element opening tags
+function startElementHandler($parser, $name, $attr) {
+
+ global $currentTag;
+
+ $currentTag = $name;
+
+}
+
+
+// The handler for the character data
+function cdataHandler($parser, $data) {
+
+ global $currentTag, $usernameValue, $sessionIDValue, $levelValue;
+
+ if (strcmp($currentTag, "USERNAME") == 0) {
+
+ $usernameValue .= $data;
+
+ } else if (strcmp($currentTag, "SESSION_ID") == 0) {
+
+ $sessionIDValue .= $data;
+
+ } else if (strcmp($currentTag, "USER_LEVEL") == 0) {
+
+ $levelValue .= $data;
+
+ }
+
+}
+
+// The handler for the element closing tags
+function endElementHandler($parser, $name) {
+
+ global $username, $usernameValue, $sessionID, $sessionIDValue, $level, $levelValue;
+
+ if (strcmp($name, "USERNAME") == 0) {
+
+ $username = $usernameValue;
+ $usernameValue = "";
+
+ } else if (strcmp($name, "SESSION_ID") == 0) {
+
+ $sessionID = $sessionIDValue;
+ $sessionIDValue = "";
+
+ } else if (strcmp($name, "USER_LEVEL") == 0) {
+
+ $level = $levelValue;
+ $levelValue = "";
+
+ }
+
+}
+
+// Create the XML parser
+$parser = xml_parser_create();
+
+// Register the start and end element handlers
+xml_set_element_handler($parser, "startElementHandler", "endElementHandler");
+
+// Register the character data parser
+xml_set_character_data_handler($parser, "cdataHandler");
+
+if (!xml_parse($parser, $HTTP_RAW_POST_DATA, true)) {
+
+ echo "falseXML packet was invalid. Please try again.";
+ exit;
+
+}
+
+// OK, finished parsing the XML
+xml_parser_free($parser);
+
+// Query the database
+$stmt = "SELECT session_id, user_type FROM fb_user WHERE username='$username'";
+$result = @mysql_query($stmt, $db);
+
+if ($result == 0) {
+
+ echo "falseThis is a restricted area. You need to login before you can continue. Please enter your username and password.";
+ exit;
+
+}
+
+if (@mysql_num_rows($result) <= 0) {
+
+ echo "falseThis is a restricted area. You need to login before you can continue. Please enter your username and password.";
+ return;
+
+}
+
+$row = @mysql_fetch_array($result);
+
+if ($row['session_id'] == $sessionID) {
+
+ if ($level == "user") {
+
+ echo "trueUser is logged in.";
+ exit;
+
+ }
+
+ if ($row['user_type'] != "administrator") {
+
+ echo "falseYou must be an Administrator to edit FlashBlog's configuration.";
+ exit;
+
+ }
+
+ echo "trueUser is logged in.";
+ exit;
+
+}
+
+echo "falseThis is a restricted area. You need to login before you can continue. Please enter your username and password.";
+
+?>
diff --git a/chapter10/Chapter 10/flashblog files/flashblog_li_start.fla b/chapter10/Chapter 10/flashblog files/flashblog_li_start.fla
new file mode 100644
index 0000000..9b0f08b
Binary files /dev/null and b/chapter10/Chapter 10/flashblog files/flashblog_li_start.fla differ
diff --git a/chapter10/Chapter 10/flashblog files/flashblog_login_finish.fla b/chapter10/Chapter 10/flashblog files/flashblog_login_finish.fla
new file mode 100644
index 0000000..53d1a6a
Binary files /dev/null and b/chapter10/Chapter 10/flashblog files/flashblog_login_finish.fla differ
diff --git a/chapter10/Chapter 10/flashblog files/flashblog_login_finish.swf b/chapter10/Chapter 10/flashblog files/flashblog_login_finish.swf
new file mode 100644
index 0000000..c403b48
Binary files /dev/null and b/chapter10/Chapter 10/flashblog files/flashblog_login_finish.swf differ
diff --git a/chapter10/Chapter 10/flashblog files/flashblog_logout_finish.fla b/chapter10/Chapter 10/flashblog files/flashblog_logout_finish.fla
new file mode 100644
index 0000000..a956a22
Binary files /dev/null and b/chapter10/Chapter 10/flashblog files/flashblog_logout_finish.fla differ
diff --git a/chapter10/Chapter 10/flashblog files/flashblog_logout_start.fla b/chapter10/Chapter 10/flashblog files/flashblog_logout_start.fla
new file mode 100644
index 0000000..0f52bf1
Binary files /dev/null and b/chapter10/Chapter 10/flashblog files/flashblog_logout_start.fla differ
diff --git a/chapter10/Chapter 10/flashblog files/flashblog_secure3_start.fla b/chapter10/Chapter 10/flashblog files/flashblog_secure3_start.fla
new file mode 100644
index 0000000..f6c9fe6
Binary files /dev/null and b/chapter10/Chapter 10/flashblog files/flashblog_secure3_start.fla differ
diff --git a/chapter10/Chapter 10/flashblog files/flashblog_secure_start.fla b/chapter10/Chapter 10/flashblog files/flashblog_secure_start.fla
new file mode 100644
index 0000000..cf8ba9c
Binary files /dev/null and b/chapter10/Chapter 10/flashblog files/flashblog_secure_start.fla differ
diff --git a/chapter10/Chapter 10/flashblog files/login.php b/chapter10/Chapter 10/flashblog files/login.php
new file mode 100644
index 0000000..6f846e7
--- /dev/null
+++ b/chapter10/Chapter 10/flashblog files/login.php
@@ -0,0 +1,131 @@
+falseXML packet was invalid. Please try again.";
+ exit;
+
+}
+
+// OK, finished parsing the XML
+xml_parser_free($parser);
+
+// Query the database for the username and password
+$result = @mysql_query("SELECT username, password FROM fb_user WHERE username='$username';", $db);
+
+// Check the query, send an error message if the query failed and then exit the script
+if ($result == 0) {
+
+ echo "falseThe username was incorrect. Please try again.";
+ exit;
+
+}
+
+// Check that at least one row was returned, if it wasn't, inform the SWF of an error
+if (@mysql_num_rows($result) <= 0) {
+
+ echo "falseThe username was incorrect. Please try again.";
+ exit;
+
+}
+
+// Retrieve the row from the database
+$row = @mysql_fetch_array($result);
+
+// Compare the username and password from the XML to the username and password from the database
+if ($password == $row['password']) {
+
+ // Generate the session id - with username, password and time in an MD5 hash
+ $sessionID = md5($username . $password . microtime());
+
+ // Update the session_id field with the new session id
+ $result = @mysql_query("UPDATE fb_user SET session_id='$sessionID' WHERE username='$username';", $db);
+
+ // Check the result
+ if ($result == 0) {
+
+ // The database failed while updating the session id
+ echo "falseDatabase failed. Please try again.";
+
+ } else {
+
+ // All is OK, the user has now logged in
+ echo "trueYou've successfully logged in.$sessionID";
+
+ }
+
+} else {
+
+ echo "falseThe password was incorrect. Please try again.";
+
+}
+
+
+?>
diff --git a/chapter10/Chapter 10/flashblog files/logout.php b/chapter10/Chapter 10/flashblog files/logout.php
new file mode 100644
index 0000000..835ff90
--- /dev/null
+++ b/chapter10/Chapter 10/flashblog files/logout.php
@@ -0,0 +1,91 @@
+
+ini_set("always_populate_raw_post_data", true);
+
+// Include the database details, and make a connection
+include("../../fb_includes/database.php");
+
+$currentTag = "";
+$username = "";
+$usernameValue = "";
+
+// The handler for the element opening tags
+function startElementHandler($parser, $name, $attr) {
+
+ global $currentTag;
+
+ $currentTag = $name;
+
+}
+
+// The handler for character data
+function cdataHandler($parser, $data) {
+
+ global $currentTag, $usernameValue;
+
+ if (strcmp($currentTag, "USERNAME") == 0) {
+
+ $usernameValue .= $data;
+
+ }
+}
+
+// The handler for the element closing tags
+function endElementHandler($parser, $name) {
+
+ global $username, $usernameValue;
+
+ if (strcmp($name, "USERNAME") == 0) {
+
+ $username = $usernameValue;
+ $usernameValue = "";
+
+ }
+
+}
+
+// Create the XML parser
+$parser = xml_parser_create();
+
+// Register the start and end element handlers
+xml_set_element_handler($parser, "startElementHandler", "endElementHandler");
+
+// Register the character data parser
+xml_set_character_data_handler($parser, "cdataHandler");
+
+// Parse the XML document
+if (!@xml_parse($parser, $HTTP_RAW_POST_DATA, true)) {
+
+ // An error occured, info the Flash file, and exit the script
+ echo "falseXML packet was invalid. Please try again.";
+ exit;
+
+}
+
+// Ok, finished parsing the XML, free the parser
+xml_parser_free($parser);
+
+if ($username == "") {
+
+ // The username didn't exist, but we need it to user in the query
+ echo "falseAn error occured while removing you from the system. Please close the browser window.";
+ exit;
+
+}
+
+// Update the database
+$stmt = "UPDATE fb_user SET session_id=0 WHERE username='$username'";
+$result = @mysql_query($stmt, $db);
+
+// Check the query was successful
+if ($result == 0) {
+
+ // Query failed, return a message
+ echo "falseAn error occured while removing you from the system. Please close the browser window.";
+ exit;
+
+}
+
+// All is ok, the user has been logged out of the system
+echo "trueYou've been logged out of the system.";
+
+?>
\ No newline at end of file
diff --git a/chapter10/Chapter 10/tutorial files/checkBox_final.fla b/chapter10/Chapter 10/tutorial files/checkBox_final.fla
new file mode 100644
index 0000000..32fbb24
Binary files /dev/null and b/chapter10/Chapter 10/tutorial files/checkBox_final.fla differ
diff --git a/chapter10/Chapter 10/tutorial files/checkBox_start.fla b/chapter10/Chapter 10/tutorial files/checkBox_start.fla
new file mode 100644
index 0000000..e68ba74
Binary files /dev/null and b/chapter10/Chapter 10/tutorial files/checkBox_start.fla differ
diff --git a/chapter10/Chapter 10/tutorial files/fonts_final.fla b/chapter10/Chapter 10/tutorial files/fonts_final.fla
new file mode 100644
index 0000000..719e322
Binary files /dev/null and b/chapter10/Chapter 10/tutorial files/fonts_final.fla differ
diff --git a/chapter10/Chapter 10/tutorial files/fonts_start.fla b/chapter10/Chapter 10/tutorial files/fonts_start.fla
new file mode 100644
index 0000000..0194d60
Binary files /dev/null and b/chapter10/Chapter 10/tutorial files/fonts_start.fla differ
diff --git a/chapter10/Chapter 10/tutorial files/shared_objects_final.fla b/chapter10/Chapter 10/tutorial files/shared_objects_final.fla
new file mode 100644
index 0000000..eef31fb
Binary files /dev/null and b/chapter10/Chapter 10/tutorial files/shared_objects_final.fla differ
diff --git a/chapter10/Chapter 10/tutorial files/shared_objects_start.fla b/chapter10/Chapter 10/tutorial files/shared_objects_start.fla
new file mode 100644
index 0000000..6c9c68b
Binary files /dev/null and b/chapter10/Chapter 10/tutorial files/shared_objects_start.fla differ
diff --git a/chapter11.sit b/chapter11.sit
new file mode 100644
index 0000000..4e20ff8
Binary files /dev/null and b/chapter11.sit differ
diff --git a/chapter11/Chapter 11/comments.xml b/chapter11/Chapter 11/comments.xml
new file mode 100644
index 0000000..b6c1490
--- /dev/null
+++ b/chapter11/Chapter 11/comments.xml
@@ -0,0 +1,27 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/chapter11/Chapter 11/drawing_curves.fla b/chapter11/Chapter 11/drawing_curves.fla
new file mode 100644
index 0000000..5533834
Binary files /dev/null and b/chapter11/Chapter 11/drawing_curves.fla differ
diff --git a/chapter11/Chapter 11/drawing_lines.fla b/chapter11/Chapter 11/drawing_lines.fla
new file mode 100644
index 0000000..80a0305
Binary files /dev/null and b/chapter11/Chapter 11/drawing_lines.fla differ
diff --git a/chapter11/Chapter 11/flash_images.fla b/chapter11/Chapter 11/flash_images.fla
new file mode 100644
index 0000000..027ebb9
Binary files /dev/null and b/chapter11/Chapter 11/flash_images.fla differ
diff --git a/chapter11/Chapter 11/flash_images_2.fla b/chapter11/Chapter 11/flash_images_2.fla
new file mode 100644
index 0000000..82bbfa1
Binary files /dev/null and b/chapter11/Chapter 11/flash_images_2.fla differ
diff --git a/chapter11/Chapter 11/loadtest.fla b/chapter11/Chapter 11/loadtest.fla
new file mode 100644
index 0000000..285ffd5
Binary files /dev/null and b/chapter11/Chapter 11/loadtest.fla differ
diff --git a/chapter11/Chapter 11/loadtest.swf b/chapter11/Chapter 11/loadtest.swf
new file mode 100644
index 0000000..2606b87
Binary files /dev/null and b/chapter11/Chapter 11/loadtest.swf differ
diff --git a/chapter11/Chapter 11/test.txt b/chapter11/Chapter 11/test.txt
new file mode 100644
index 0000000..702027c
--- /dev/null
+++ b/chapter11/Chapter 11/test.txt
@@ -0,0 +1 @@
+&message=Hello from the text file
\ No newline at end of file
diff --git a/contributing.md b/contributing.md
new file mode 100644
index 0000000..f6005ad
--- /dev/null
+++ b/contributing.md
@@ -0,0 +1,14 @@
+# Contributing to Apress Source Code
+
+Copyright for Apress source code belongs to the author(s). However, under fair use you are encouraged to fork and contribute minor corrections and updates for the benefit of the author(s) and other readers.
+
+## How to Contribute
+
+1. Make sure you have a GitHub account.
+2. Fork the repository for the relevant book.
+3. Create a new branch on which to make your change, e.g.
+`git checkout -b my_code_contribution`
+4. Commit your change. Include a commit message describing the correction. Please note that if your commit message is not clear, the correction will not be accepted.
+5. Submit a pull request.
+
+Thank you for your contribution!
\ No newline at end of file
diff --git a/fdn_app.sit b/fdn_app.sit
new file mode 100644
index 0000000..af004f0
Binary files /dev/null and b/fdn_app.sit differ
diff --git a/fdn_app.zip b/fdn_app.zip
new file mode 100644
index 0000000..93267bc
Binary files /dev/null and b/fdn_app.zip differ