Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
//ini_set('display_errors', 1);
$db = new SQLite3('cheapvps-comparison.db');
/*
CREATE TABLE "offers" (
"created_at" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
"url" text NOT NULL,
"post_type" integer NOT NULL,
"location" text NULL,
"provider" text NULL,
"per_mo" real NULL,
"per_yr" real NULL,
"cpus" integer NULL,
"ram" integer NULL,
"swap" integer NULL,
"storage" integer NOT NULL,
"storage_type" integer NULL,
"uplink_speed" integer NULL,
"bandwidth" integer NULL,
"ipv4" integer NULL,
"ipv6" integer NULL
);
types:
0 - shared
1 - reseller
2 - openvz
3 - kvm or xen
4 - openvz pool
5 - free shared
storage types:
0 - hdd
1 - ssd
2 - cached ssd
3 - raid-10 ssd
prices are in usd cents - convert them to usd
ram is in mib
storage is in gb
uplink speed is in mbps
bandwidth is in mb
*/
// default query, can be modified later
$query = 'SELECT post_type, location, url, provider, per_mo, per_yr, cpus, ram, swap, storage, storage_type, bandwidth, uplink_speed, ipv4 from offers where post_type = 2 or post_type = 3 order by per_yr, ram, per_mo, storage desc limit 50';
if(isset($_GET['query'])) {
$query = $_GET['query'];
} else if(!empty($_POST)) {
// make a new thing
// using escape strings, this is gross I know
$insertQuery = 'INSERT INTO offers(';
$arrayKeys = array_keys($_POST);
$arrayKeysLength = count($arrayKeys);
foreach($arrayKeys as $i => $key) {
$insertQuery .= $db->escapeString($key) . ($i !== ($arrayKeysLength - 1) ? ', ' : '');
}
$insertQuery .= ') VALUES(';
foreach($arrayKeys as $i => $key) {
if($_POST[$key] === '') {
$finalKey = 'NULL';
} else {
$finalKey = '\'' . $db->escapeString($_POST[$key]) . '\'';
}
$insertQuery .= $finalKey . ($i !== ($arrayKeysLength - 1) ? ', ' : '');
}
$insertQuery .= ');';
//print_r($insertQuery);
$result = $db->exec($insertQuery);
$error = $db->lastErrorMsg();
if($error !== 'not an error') {
header('Content-Type: text/plain');
http_response_code(500);
exit($error);
}
}
$queryLower = strtolower($query);
// check that the first 6 characters are not select in any case, and that there is a semicolon but the semicolon isn't at the end of the string
if((substr($queryLower, 0, 6) !== 'select' && substr($queryLower, 0, 6) !== 'update') || (strpos($query, ';') && strpos($query, ';') !== (strlen($query) - 1))) {
header('Content-Type: text/plain');
http_response_code(400);
exit('don\'t use semicolons and don\'t try to make a query that isn\'t a select');
}
$result = $db->query($query);
// results will be fetched later
if(!$result) {
header('Content-Type: text/plain');
http_response_code(500);
exit($db->lastErrorMsg());
}
$numColumns = $result->numColumns();
?><!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="icon" href="data:;base64,iVBORw0KGgo=">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}
h1 {
font-size: 72px;
margin: 0;
margin-bottom: 10px;
}
h2 {
font-size: 36px;
margin: 0;
margin-bottom: 10px;
}
.tiny {
font-size: 10px;
}
table, th, td {
border-collapse: collapse;
border: 1px solid black;
}
td {
text-align: center;
}
th[title] {
cursor: help;
}
input, select {
margin-bottom: 5px;
}
input[name=query] {
width: 800px;
}
button {
display: block;
margin-bottom: 5px;
}
@media screen and (max-width: 800px) {
input[name=query] {
width: 100%;
}
table {
width: 100%;
}
}
</style>
<title>vps comparison!!!!!!!!!! (HEAP)</title>
</head>
<body>
<h1>heap vps omparison!!!!!!!!!!!!!</h1>
<h2 id="insert">Insert</h2>
<form action="#insert" method="post">
URL: <input type="text" name="url" placeholder="URL"<?php
if(isset($_POST['url'])) {
?> value="<?= htmlspecialchars($_POST['url']) ?>"<?php
}
?>><br>
Provider: <input type="text" name="provider" placeholder="Provider name"<?php
if(isset($_POST['provider'])) {
?> value="<?= htmlspecialchars($_POST['provider']) ?>"<?php
}
?>><br>
Type: <select name="post_type">
<option value="0"<?php
if(isset($_POST['post_type']) && $_POST['post_type'] === '0') {
?> selected<?php
}
?>>Shared</option>
<option value="1"<?php
if(isset($_POST['post_type']) && $_POST['post_type'] === '1') {
?> selected<?php
}
?>>Reseller</option>
<option value="2"<?php
if(isset($_POST['post_type']) && $_POST['post_type'] === '2') {
?> selected<?php
}
?>>OpenVZ</option>
<option value="3"<?php
if(isset($_POST['post_type']) && $_POST['post_type'] === '3') {
?> selected<?php
}
?>>KVM</option>
<option value="4"<?php
if(isset($_POST['post_type']) && $_POST['post_type'] === '4') {
?> selected<?php
}
?>>OpenVZ pool</option>
<option value="5"<?php
if(isset($_POST['post_type']) && $_POST['post_type'] === '5') {
?> selected<?php
}
?>>Free shared</option>
</select><br>
Location(s): <input type="text" name="location" placeholder="Location(s)"<?php
if(isset($_POST['location'])) {
?> value="<?= htmlspecialchars($_POST['location']) ?>"<?php
}
?>><br>
$/mo: <input type="number" name="per_mo" step=".01" placeholder="$/mo, leave blank if none"<?php
if(isset($_POST['per_mo'])) {
?> value="<?= htmlspecialchars($_POST['per_mo']) ?>"<?php
}
?>><br>
$/yr: <input type="number" name="per_yr" step=".01" placeholder="$/yr, leave blank if none"<?php
if(isset($_POST['per_yr'])) {
?> value="<?= htmlspecialchars($_POST['per_yr']) ?>"<?php
}
?>><br>
CPUs: <input type="number" name="cpus" placeholder="CPUs, leave blank if unknown"<?php
if(isset($_POST['cpus'])) {
?> value="<?= htmlspecialchars($_POST['cpus']) ?>"<?php
}
?>><br>
RAM in MiB: <input type="number" name="ram" placeholder="RAM in MiB, leave blank if unknown"<?php
if(isset($_POST['ram'])) {
?> value="<?= htmlspecialchars($_POST['ram']) ?>"<?php
}
?>><br>
Swap in MiB: <input type="number" name="swap" placeholder="Swap in MiB (OpenVZ only), leave blank if unknown"<?php
if(isset($_POST['swap'])) {
?> value="<?= htmlspecialchars($_POST['swap']) ?>"<?php
}
?>><br>
Storage in GB: <input type="number" name="storage" placeholder="Space in GB"<?php
if(isset($_POST['storage'])) {
?> value="<?= htmlspecialchars($_POST['storage']) ?>"<?php
}
?>><br>
Storage type: <select name="storage_type">
<option value="">Unknown</option>
<option value="0"<?php
if(isset($_POST['storage_type']) && $_POST['storage_type'] === '0') {
?> selected<?php
}
?>>HDD</option>
<option value="1"<?php
if(isset($_POST['storage_type']) && $_POST['storage_type'] === '1') {
?> selected<?php
}
?>>SSD</option>
<option value="2"<?php
if(isset($_POST['storage_type']) && $_POST['storage_type'] === '2') {
?> selected<?php
}
?>>Cached SSD</option>
<option value="3"<?php
if(isset($_POST['storage_type']) && $_POST['storage_type'] === '3') {
?> selected<?php
}
?>>RAID-10 SSD</option>
</select><br>
Bandwidth in GB: <input type="number" name="bandwidth" placeholder="Bandwidth, leave blank if unknown"<?php
if(isset($_POST['bandwidth'])) {
?> value="<?= htmlspecialchars($_POST['bandwidth']) ?>"<?php
}
?>><br>
Uplink speed in Mbps: <input type="number" name="uplink_speed" placeholder="Uplink speed, leave blank if unknown"<?php
if(isset($_POST['uplink_speed'])) {
?> value="<?= htmlspecialchars($_POST['uplink_speed']) ?>"<?php
}
?>><br>
IPv4s (the amount of IPv4 addresses): <input type="number" name="ipv4" placeholder="IPv4, leave blank if unknown"<?php
if(isset($_POST['ipv4'])) {
?> value="<?= htmlspecialchars($_POST['ipv4']) ?>"<?php
}
?>><br>
IPv6s (the amount of IPv4 addresses): <input type="number" name="ipv6" placeholder="IPv6, leave blank if unknown"<?php
if(isset($_POST['ipv6'])) {
// ?> value="<?= htmlspecialchars($_POST['ipv6']) ?>"<?php
}
?>><br>
<button>Go</button>
</form>
<h2 id="search">Search</h2>
<form action="#search" method="get">
<input type="text" name="query" placeholder="SQL search query" value="<?= htmlspecialchars($query) ?>">
<button>Go</button>
</form>
<p>Presets:
<ul>
<li><a href="?#search">Search for OpenVZ/KVM VPSes (Default)</a></li>
<li><a href="?query=SELECT+post_type%2C+location%2C+url%2C+provider%2C+per_mo%2C+per_yr%2C+cpus%2C+ram%2C+swap%2C+storage%2C+storage_type%2C+bandwidth%2C+uplink_speed%2C+ipv4+from+offers+where+post_type+%3D+0+or+post_type+%3D+1+order+by+per_yr%2C+ram%2C+per_mo%2C+storage+desc+limit+50#search">Search for shared/reseller hosting</a></li>
<li><a href="?query=SELECT+post_type%2C+location%2C+url%2C+provider%2C+per_mo%2C+per_yr%2C+cpus%2C+ram%2C+swap%2C+storage%2C+storage_type%2C+bandwidth%2C+uplink_speed%2C+ipv4+from+offers+where+post_type+%3D+5+order+by+per_yr%2C+ram%2C+per_mo%2C+storage+desc+limit+50#search">Search for free shared hosting</a></li>
<li><a href="?query=SELECT+post_type%2C+location%2C+url%2C+provider%2C+per_mo%2C+per_yr%2C+cpus%2C+ram%2C+swap%2C+storage%2C+storage_type%2C+bandwidth%2C+uplink_speed%2C+ipv4+from+offers+where+post_type+%3D+4+order+by+per_yr%2C+ram%2C+per_mo%2C+storage+desc+limit+50#search">Search for OpenVZ pools</a></li>
</ul></p>
<table>
<thead>
<tr>
<?php
for($i = 0; $i < $numColumns; $i++) {
$columnName = $result->columnName($i);
switch($columnName) {
case 'created_at':
?><th>Date posted</th><?php
break;
case 'url':
?><th>URL</th><?php
break;
case 'post_type':
?><th title="Type can be shared hosting, reseller hosting, OpenVZ, or KVM. Shared and reseller hosting are PHP and Apache-only, while OpenVZ and KVM give you a Linux environment. OpenVZs use a shared kernel that is probably very old and cannot be modified in any way, but KVMs run their own kernel, meaning you can even run operating systems other than Linux on them in some cases.">Type <span class="tiny">?</span></th><?php
break;
case 'location':
?><th title="Location matters, closer = faster. At least select a location close to you, or close to whoever will be using this service. If you live in the United States, it's recommended that you select a central US city like Chicago, IL.">Location <span class="tiny">?</span></th><?php
break;
case 'provider':
?><th>Provider</th><?php
break;
case 'per_mo':
?><th>$/mo</th><?php
break;
case 'per_yr':
?><th>$/yr</th><?php
break;
case 'cpus':
?><th>CPUs</th><?php
break;
case 'ram':
?><th>RAM</th><?php
break;
case 'swap':
?><th title="Swap, or vSwap, is for OpenVZ only.">Swap <span class="tiny">?</span></th><?php
break;
case 'storage':
?><th>Space</th><?php
break;
case 'storage_type':
?><th title="Storage type can be HDD, SSD, cached SSD, RAID-10 SSD, I don't know. Just don't choose HDD unless you are fine with disk access being slow (which won't be much of a problem with Linux disk caching).">Storage type <span class="tiny">?</span></th><?php
break;
case 'uplink_speed':
?><th>Uplink speed</th><?php
break;
case 'bandwidth':
?><th>Bandwidth</th><?php
break;
case 'ipv4':
?><th>IPv4s</th><?php
break;
case 'ipv6':
?><th>IPv6s</th><?php
break;
default:
if(!empty($columnName)) {
?><th><?= htmlspecialchars($columnName) ?></th><?php
}
}
}
?>
</tr>
</thead>
<tbody>
<?php
while($row = $result->fetchArray()) {
?><tr><?php
for($i = 0; $i < $numColumns; $i++) {
$columnName = $result->columnName($i);
?><td><?php
switch($columnName) {
case 'post_type':
switch($row[$columnName]) {
case 0:
echo 'Shared';
break;
case 1:
echo 'Reseller';
break;
case 2:
echo 'OpenVZ';
break;
case 3:
echo 'KVM';
break;
case 4:
echo 'OpenVZ pool';
break;
case 5:
echo 'Free shared';
break;
default:
echo $row[$columnName];
}
break;
case 'url':
?><a href="<?= htmlspecialchars($row[$columnName]) ?>">Go</a><?php
break;
case 'storage_type':
switch($row[$columnName]) {
case 0:
echo 'HDD';
break;
case 1:
echo 'SSD';
break;
case 2:
echo 'Cached SSD';
break;
case 3:
echo 'RAID-10 SSD';
break;
default:
echo $row[$columnName];
}
break;
default:
echo htmlspecialchars($row[$columnName]);
}
?></td><?php
}
?></tr><?php
}
?>
</tbody>
</table>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.