The perl code required an external (but very small) perl Module, so I figured it's probably less trouble to just rewrite it in PHP quickly. It's not like it's complex or anything.
Here's the script:
<?php
// Define settings
$dbserver = "localhost"; // Change as required
$dbname = "myRokuDb"; // Whatever DB you have access to
$dbuser = "someuser"; // User to connect to DB as
$dbpass = "dbpassword";// Password for DB user
// Connect to DB
$dbconn = mysql_connect($dbserver, $dbuser, $dbpass);
if (!$dbconn) die("Error connecting to database!");
if (!mysql_select_db($dbname)) die("Error selecting database $dbname");
// Get args
$channel = !empty($_REQUEST['channel']) ? mysql_real_escape_string($_REQUEST['channel']) : "";
$uuid = !empty($_REQUEST['uuid']) ? mysql_real_escape_string($_REQUEST['uuid']) : "";
$key = !empty($_REQUEST['key']) ? mysql_real_escape_string($_REQUEST['key']) : "";
$value = !empty($_REQUEST['value']) ? mysql_real_escape_string($_REQUEST['value']) : "";
$ip = mysql_real_escape_string($_SERVER['REMOTE_ADDR']);
// Verify args
if (empty($channel)) die("Missing or invalid paramater 1");
if (empty($uuid) or !preg_match('/^[0-9a-f]{32}$/i',$uuid)) die("Missing or invalid paramater 2");
if (empty($key)) die("Missing or invalid paramater 3");
if (empty($value)) die("Missing or invalid paramater 4");
// Store data
$insert_sql = "INSERT INTO storedata (`time`, `channel`, `ip`, `uuid`, `key`, `value`) VALUES (NOW(),'$channel','$ip','$uuid','$key','$value')";
$result = mysql_query($insert_sql); // Stupid default PHP mysql functions without binding...
if (!$result) die("Error saving data!");
print "Data saved";
?>
Drop that into a .php file on your webhost, and configure your database
Here's the table schema:
CREATE TABLE `storedata` (
`id` bigint(20) NOT NULL auto_increment,
`channel` varchar(20) NOT NULL default 'unspecified',
`ip` varchar(15) NOT NULL default '0.0.0.0',
`uuid` char(32) NOT NULL default '',
`time` timestamp NOT NULL default CURRENT_TIMESTAMP,
`key` varchar(255) NOT NULL default '',
`value` blob NOT NULL,
PRIMARY KEY (`id`)
);
You'll need to generate a random uuid string in the channel to use this, which this can do:
uuid = ""
for i=1 to 32
o = RND(16)
if o <= 10
o = o + 47
else
o = o + 96 - 10
end if
uuid = uuid + CHR(o)
end for
(No, it's not a correct UUID)
I generally generate one per run of a channel, so subsequent requests to the data storage script from the same channel run can be identified. You can omit this and just make uuid = STRING(32,"0") for a 32 character string of zeroes.
The actual submission looks something like this on mine:
http = CreateObject("roUrlTransfer")
http.setUrl(YOUR_SCRIPT_URL_HERE)
http.InitClientCertificates() ' if https without a real cert
http.EnablePeerVerification(false) ' if https without a real cert
http.EnableHostVerification(false) ' if https without a real cert
sPostData = "channel=fontsizer&uuid="+http.urlEncode(uuid)+"&key="+http.urlEncode("f:"+sFont+sDefinition)+"&value="+http.urlEncode(sFS)
http.postFromString(sPostData)
Of course, change the key and value portion of the post data before posting.
Whew.
-- GandK Labs
Check out Reversi! in the channel store!