Here is some very very rough php/mysql code I hacked together last year to create a demo linking app. It is lacking in several areas, for example, it does not associate the device unique id with the linking code, linking is done with a token and the user email address. I'm not checking that the generated code is unique at the time it is generated, I think I'm checking that somewhere though, if not, then the code is hoping that the sheer size of the range of random numbers will avoid a collision. Of course, you need a server with php/mysql and a little bit of know-how.
The following code is mostly the intellectual property of Joel Braverman (c) 2011 and not the property of Roku, inc, and is provided by Joel Braverman without support or warranty for unlimited modification and redistribution throughout the entire universe by all entities and beings, with the sole restriction that it may not be used for evil purposes, for example taking over a galaxy or enslaving furry aliens on the moons of Endor would be a violation of the license:
form used to link device to server, index.html:
<html>
<body>
<form action="savecode.php" method="post">
Please Enter Firstname: <input type="text" name="firstname" /><br>
Please Enter Lastname: <input type="text" name="lastname" /><br>
Please Enter an email address: <input type="text" name="email" /><br>
Please enter a password: <input type="text" name="password" /><br>
Please enter the Code displayed on your Roku Screen: <input type="text" name="code" /><br>
<input type="submit" value="Click to store code"/>
</form>
</body>
</html>
Store the code in a MySQL database, savecode.php:
<?
// Define settings
$dbserver = "mysql"; // Change as required
$dbname = "mydatabase"; // Whatever DB you have access to
$dbuser = "myusername"; // User to connect to DB as
$dbpass = "mypassword";// Password for DB user
// Connect to DB
$dbconn = mysql_connect("mysql","myusername","mypassword");
if (!$dbconn) die("Error connecting to database!");
if (!mysql_select_db($dbname)) die("Error selecting database $dbname");
// Get args
$email = !empty($_REQUEST['email']) ? mysql_real_escape_string($_REQUEST['email']) : "";
$password = !empty($_REQUEST['password']) ? mysql_real_escape_string($_REQUEST['password']) : "";
$code = !empty($_REQUEST['code']) ? mysql_real_escape_string($_REQUEST['code']) : "";
$firstname = !empty($_REQUEST['firstname']) ? mysql_real_escape_string($_REQUEST['firstname']) : "";
$lastname = !empty($_REQUEST['lastname']) ? mysql_real_escape_string($_REQUEST['lastname']) : "";
// Verify args
if (empty($email)) die("Missing or invalid paramater 1");
if (empty($password)) die("Missing or invalid paramater 2");
if (empty($code)) die("Missing or invalid paramater 3");
if (empty($firstname)) die("Missing or invalid paramater 4");
if (empty($lastname)) die("Missing or invalid paramater 5");
// Store data
$sql = "INSERT INTO `mydatabase`.`users` (`firstname`, `lastname`, `email`, `password`, `code`) VALUES ('$firstname','$lastname','$email','$password','$code')";
$result = mysql_query($sql);
if (!$result) die(mysql_errno($link) . ": " . mysql_error($link));
?>
url the Roku uses to check if the user has entered their unique code, checkcode.php
<?
// Define settings
$dbserver = "mysql"; // Change as required
$dbname = "mydatabase"; // Whatever DB you have access to
$dbuser = "myusername"; // User to connect to DB as
$dbpass = "mypassword";// Password for DB user
$code="";
// Connect to DB
$dbconn = mysql_connect("mysql","myusername","mypassword");
if (!$dbconn) die("Error connecting to database!");
if (!mysql_select_db($dbname)) die("Error selecting database $dbname");
// Get args
$code = !empty($_REQUEST['code']) ? mysql_real_escape_string($_REQUEST['code']) : "";
// Verify args
if (empty($code)) die("Missing or invalid Code");
$sql = "SELECT * FROM `users` WHERE code =\"" . $code."\"";
//echo "sql follows";
//echo "<br>";
//echo $sql;
// Get a specific result from the "example" table
$result = mysql_query($sql) or die(mysql_error());
// get the first (and hopefully only) entry from the result
$row = mysql_fetch_array($result);
// Print out the contents of each row into a table
echo $row['code'];
?>
generate a random code for linking: makepin.php
<?php
$random=rand(1679616, 60466175);
print base_convert($random,10,36);
?>
mysql database structure - not sure if the devices table is actually used by the php code:
-- phpMyAdmin SQL Dump
-- version 2.11.9.6
-- http://www.phpmyadmin.net
--
-- Host: mysql
-- Generation Time: Jan 29, 2012 at 03:14 AM
-- Server version: 4.1.14
-- PHP Version: 5.2.12
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
--
-- Database: `mydatabase`
--
-- --------------------------------------------------------
--
-- Table structure for table `udevices`
--
CREATE TABLE IF NOT EXISTS `udevices` (
`email` varchar(100) NOT NULL default '',
`dev1` varchar(10) NOT NULL default '',
`dev2` varchar(10) NOT NULL default '',
`dev3` varchar(10) NOT NULL default '',
`dev4` varchar(10) NOT NULL default '',
`dev5` varchar(10) NOT NULL default '',
PRIMARY KEY (`email`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- Table structure for table `users`
--
CREATE TABLE IF NOT EXISTS `users` (
`firstname` varchar(50) NOT NULL default '',
`lastname` varchar(50) NOT NULL default '',
`email` varchar(100) NOT NULL default '',
`password` varchar(25) NOT NULL default '',
`code` varchar(6) NOT NULL default '',
PRIMARY KEY (`email`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='no comment';