Validate user input

This commit is contained in:
Ruan 2015-06-08 17:44:53 +02:00
parent 07b3a63f33
commit 0848871c67

View File

@ -1,7 +1,13 @@
<?php <?php
if (isset($_POST['name'], $_POST['table'])) { if (isset($_POST['name'], $_POST['table'])) {
require 'includes/page.php'; require 'includes/page.php';
$name = $_POST['name']; // user input $name = $_POST['name'];
// validate user input
if (strlen($name) > 16 || !preg_match("/[0-9a-zA-Z_]/", $name)) {
echo('Invalid name.');
return;
}
global $table_bans, $table_history, $conn; global $table_bans, $table_history, $conn;
$stmt = $conn->prepare("SELECT name,uuid FROM " . $table_history . " WHERE name=? ORDER BY date LIMIT 1"); $stmt = $conn->prepare("SELECT name,uuid FROM " . $table_history . " WHERE name=? ORDER BY date LIMIT 1");
if ($stmt->execute(array($name))) { if ($stmt->execute(array($name))) {