Registering users on a website

// change these to match your databasedefine('DB_HOSTNAME', "localhost");define('DB_DATABASE', "test");define('DB_USERNAME', "myusername");define('DB_PASSWORD', "mypassword"); // Code starts hereif (isset($_SERVER['HTTP_X_SECONDLIFE_OBJECT_KEY'])){ // store entry on MySQL database try { $db = new PDO('mysql:host=' . DB_HOSTNAME . ';dbname=' . DB_DATABASE, DB_USERNAME, DB_PASSWORD); } catch(PDOException $e) { header("HTTP/1.0 503 Service Unavailable"); printf("Connect failed: %s\n", $e->getMessage()); exit(); } if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'register') { $query = $db->prepare("REPLACE INTO avatars (avatarKey, avatarName, location) VALUES (:avatarKey, :avatarName, :secondlifeRegion);"); try { $query->execute(array(':avatarKey' => $_REQUEST['avatarKey'], ':avatarName' => $_REQUEST['avatarName'], ':secondlifeRegion' => $_SERVER['HTTP_X_SECONDLIFE_REGION'])); } catch(PDOException $e) { header("HTTP/1.0 503 Service Unavailable"); printf("REPLACE query failed: '%s'\n", $e->getMessage()); exit(); } // The following will send info back to SL header("HTTP/1.0 200 OK"); header("Content-type: text/plain; charset=utf-8"); echo "Avatar " . $_REQUEST['avatarName'] . " (" . $_REQUEST['avatarKey'] . ") updated at location " . $_SERVER['HTTP_X_SECONDLIFE_REGION']; }}else{ header("HTTP/1.0 405 Method Not Allowed"); echo "Request did not come from Second Life/OpenSimulator";}

Thanks to Aleena for some important security fixes and to waters for catching a typo.

Print Friendly, PDF & Email
| ← Previous | |
%d bloggers like this: