I've created this code to send a response to Flash which can be handled with AS2/AS3:
<?php
/**
* Basic server-side API controls for Flash-PHP communication
* @author Marty Wallace
* @version 1.0.2
*/
class API
{
// MySQL
private $con;
private $sql_hostname = '';
private $sql_username = '';
private $sql_password = '';
private $sql_database = '';
// Properties
public $response;
/**
* Constructor
*/
public function __construct()
{
// Attempt connection
$this->con = mysql_connect(
$this->sql_hostname,
$this->sql_username,
$this->sql_password
);
// Connection could not be established
if(!$this->con)
{
$this->response = array(
"status" => "no_connection",
"message" => "Could not connect to MySQL, try again later."
);
$this->respond();
}
// Select database
mysql_select_db($this->sql_database);
}
/**
* Send response back to Flash
*/
public function respond()
{
$ar = array();
foreach($this->response as $key => $value)
array_push($ar, $key . "=" . $value);
die(implode("&", $ar));
}
}
?>
I'm not that great with PHP and the respond()
function seems like it could be written a little better.. Any suggestions?