示例#1
0
function createUID($table, $field)
{
    do {
        $uid = (int) openssl_random_pseudo_bytes(4);
        echo "Unique ID: " . $uid . " <br>";
    } while (!uniqueInTable($table, $field, $uid));
    return $uid;
}
示例#2
0
<!DOCTYPE html>
<html>
<head>
<title>Fridge Genie || Register</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
</head>
<body>
<div id="main">

<?php 
if (!empty($_POST['username']) && !empty($_POST['password'])) {
    $username = mysql_real_escape_string($_POST['username']);
    $password = mysql_real_escape_string($_POST['password']);
    $email = mysql_real_escape_string($_POST['email']);
    if (!uniqueInTable('users', 'username', $username)) {
        ?>
        <h1>Error: Username Already Taken</h1>
        <p>Please <a href="register.php">click here</a> to try again</p>    
        <?php 
    } else {
        $registerQuery = registerUser($username, $password, $email);
        if ($registerQuery) {
            echo "<h1>Success!</h1>";
            echo "<p>Please <a href='index.php'>click here</a> to login</p>";
        } else {
            echo "<h1>Error!</h1>";
            echo "<p>Registration failed, <a href='register.php'>click here</a> to try again</p>";
        }
    }
} else {