Restructure & change a lot of this
This commit is contained in:
8 files changed
+139
-132
No files matched your search
+52
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
include __DIR__ . "/incl/util.php";
|
||||
header("Content-Type: text/plain");
|
||||
|
||||
$time = time();
|
||||
$conn = connectToDatabase();
|
||||
$color = $_GET['color'];
|
||||
$name = $_GET['name'];
|
||||
|
||||
$color = ltrim($color, '#');
|
||||
if (!preg_match('/^[a-f0-9]{6}$/i', $color)) {
|
||||
echo "-1";
|
||||
exit;
|
||||
}
|
||||
|
||||
if (strlen($name) < 3) {
|
||||
echo "-2";
|
||||
exit;
|
||||
}
|
||||
|
||||
if (strlen($name) > 50) {
|
||||
echo "-3";
|
||||
exit;
|
||||
}
|
||||
$name = base64_encode($name);
|
||||
|
||||
$stmt = $conn->prepare("SELECT name FROM colors WHERE color = :color");
|
||||
$stmt->bindParam(':color', $color);
|
||||
$stmt->execute();
|
||||
|
||||
if ($stmt->rowCount() > 0) {
|
||||
echo "-4";
|
||||
exit;
|
||||
}
|
||||
|
||||
$stmt = $conn->prepare("SELECT name FROM colors WHERE name = :name");
|
||||
$stmt->bindParam(':name', $name);
|
||||
$stmt->execute();
|
||||
|
||||
if ($stmt->rowCount() > 0) {
|
||||
echo "-5";
|
||||
exit;
|
||||
}
|
||||
|
||||
$stmt = $conn->prepare("INSERT INTO colors (color, name, timestamp) VALUES (:color, :name, :time)");
|
||||
$stmt->bindParam(':color', $color);
|
||||
$stmt->bindParam(':name', $name);
|
||||
$stmt->bindParam(':time', $time);
|
||||
$stmt->execute();
|
||||
$lastInsertId = $conn->lastInsertId();
|
||||
|
||||
echo "1:" . $lastInsertId;
|
||||
Reference in new issue
Block a user