Source of /checkpoint/db.php


<?
if ($_SERVER['SCRIPT_FILENAME'] == __FILE__)
{
    
$allowviewsource = 1;
    require_once(
"../common.php");
    if (!isset(
$_REQUEST['viewsource']))
        
error_page("This page cannot be viewed alone.");
}

require_once(
"../mysql.php");
require_once(
"checkpoint.php");

function
GetSavedDetails($id)
{
    
$conn = db_connect("checkpoint", "checkpoint");
    
$results = db_query(sprintf("SELECT message, size, angle FROM saved WHERE id = '%s' LIMIT 1", mysql_real_escape_string($id, $conn)), $conn);
    
db_close($conn);
    if (
count($results))
        return array(
$results[0]['message'], $results[0]['size'], $results[0]['angle'] != NULL ? $results[0]['angle'] : FALSE);
    else
        return array(
"75 CHECKPOINTS LOST\n\"Not a real shortened ID\"", 12, FALSE);
}

function
randomchar()
{
    
$i = rand(0, 61);
    if (
$i 10)
        return
chr($i + ord('0'));
    else if (
$i 36)
        return
chr($i - 10 + ord('A'));
    else
        return
chr($i - 36 + ord('a'));
}

function
SaveDetails()
{
    
$params = GetParamsClean();
    
$message = $params[0];
    
$size = $params[1];
    
$angle = $params[2];
    
$conn = db_connect("checkpoint", "checkpoint");
    
# Check whether this message has already been saved
    
$results = db_query(sprintf("SELECT id FROM saved WHERE message = '%s' AND size = %lf AND angle %s LIMIT 1", mysql_real_escape_string($message, $conn), $size, $angle === FALSE ? 'IS NULL' : "= $angle"), $conn);
    if (
count($results))
    {
        
db_close($conn);
        return
$results[0]['id'];
    }
    
#generate a new id... keep on trying to insert until we find an id that's unused.
    
$id = "";
    for (
$i = 0$i 3$i++)
        
$id .= randomchar();
    
# Use mysql_query instead of my wrapper, because we want to handle errors, not fail on them
    
while (!mysql_query(sprintf("INSERT INTO saved(id, message, size, angle) VALUES('%s', '%s', %lf, %s)", mysql_real_escape_string($id, $conn), mysql_real_escape_string($message, $conn), $size, $angle === FALSE ? 'NULL' : $angle), $conn))
        
$id .= randomchar();
    
db_close($conn);
    return
$id;
}
?>

Valid HTML 4.01 StrictValid CSSLevel Triple-A conformance icon, W3C-WAI Web Content Accessibility Guidelines 1.0
Retrieved from https://​www.mrphlip.com/​checkpoint/​db.php?​viewsource=yep.
Copyright © 2006–13 Phillip Bradbury. Some rights reserved.
This page is best viewed in a web browser at a screen resolution. Attempts to do otherwise may fail miserably.
Contact me