-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathget.php
39 lines (33 loc) · 997 Bytes
/
get.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
require('config.php');
mysql_connect($config['db_host'], $config['db_user'], $config['db_pass']);
mysql_select_db($config['db_name']);
function id_lengthen($id)
{
static $map = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-';
$res = 0;
for ($i = 0; $i < strlen($id); $i++) {
$res <<= 6;
if (FALSE === ($j = strpos($map, $id[$i]))) die("Invalid ID.");
$res += $j;
}
return $res;
}
$id = isset($_GET['id']) ? $_GET['id'] : NULL;
if (!$id) die("No ID given.");
if (strlen($id) == 40)
$q = "graph_code = '".mysql_real_escape_string($id)."'";
else
$q = "graph_id = ". id_lengthen($id) ." AND private = 0";
function get_all($q)
{
$res = mysql_query($q);
if (!$res) die("Failed to get stuff from database. Sorry!");
$arr = array();
while ($row = mysql_fetch_assoc($res)) $arr[] = $row;
return $arr;
}
$d = get_all("SELECT graph_img FROM graphs WHERE $q");
if (!$d) die("Graph doesn't exist.");
header("Content-Type: image/png");
print $d[0]['graph_img'];