SQLite Database

The script below requires a SQL database called customURL.sqlite placed in the same directory as registerURL.php which has the following structure:

BEGIN TRANSACTION;
CREATE TABLE "urls" (
	 "URL" text NOT NULL,
	PRIMARY KEY("URL")
);
COMMIT;

Code: registerURL

registerURL.php
<?php
 
        //////////////////////////////////////////////////////////
        //     WaS (c) grimore.org - 2012, License: GPLv3            //
        // Please see: http://www.gnu.org/licenses/gpl.html     //
        // for legal details, rights of fair usage and          //
        // the disclaimer and warranty conditions.              //
        //////////////////////////////////////////////////////////
 
        // For privacy, you need to generate a password. You can do that
        // by issuing the following command on an *nix-like system and 
        // replace "super-duper secret password" with a secret shared between
        // this PHP script and the LSL counterpart:
        // sh$ echo "super-duper secret password" | sha1sum  | awk '{ print $1 }'
        $apiKey = 'A1364788-B702-4413-B937-7A57E32B43CE';
 
        if(!isset($_GET['apiKey']) || $_GET['apiKey'] != $apiKey) {
                throw new Exception('Invalid API key.');
                return;         
        }
        if(!isset($_GET['action'])) {
                throw new Exception('No action specified.');
                return;
        }
        switch($_GET['action']) {
                case "register":
                        if(!isset($_GET['llURL']) && !isset($_GET['shortURL'])) return;
                        $llURL = $_GET['llURL'];
                        $shortURL = $_GET['shortURL'];
                        $db = new PDO('sqlite:customURL.sqlite');
                        $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                        $q = $db->prepare("REPLACE INTO url_table(llURL, shortURL) VALUES(:llURL, :shortURL)");
                        try {
                                $q->execute(array(':llURL' => $llURL, ':shortURL' => $shortURL));
                        }
                        catch(PDOException $e) {
                                die($e->getMessage());
                        }
                        print $shortURL;
                        break;
                case "retrieve":
                        if(!isset($_GET['shortURL'])) return;
                        $shortURL = $_GET['shortURL'];
                        $db = new PDO('sqlite:customURL.sqlite');
                        $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                        $q = $db->prepare("SELECT llURL FROM url_table WHERE shortURL=:shortURL LIMIT 1");
                        try {
                                $q->execute(array(':shortURL' => $shortURL));
                                $res = $q->fetch(PDO::FETCH_OBJ); 
                        }
                        catch(PDOException $e) {
                                die($e->getMessage());
                        }
                        print $res->llURL;
                        break;
                default:
                        break;
        }
?>

secondlife/sales_agent_tool/php/registerurl.txt ยท Last modified: 2022/11/24 07:46 by 127.0.0.1

Access website using Tor Access website using i2p Wizardry and Steamworks PGP Key


For the contact, copyright, license, warranty and privacy terms for the usage of this website please see the contact, license, privacy, copyright.