Nå jeg opretter en bruger, kan jeg f.eks oprette en bruger der hedder Admin, og en mere bagefter der hedder admin, og ADmin, osv.?
Nogen der hved hvorfor ?
kode:
functions.php
function user_register($username, $password)
{
$query = mysql_query("SELECT username FROM user WHERE username='$username' limit 1");
while($row = mysql_fetch_assoc($query)) //Lav en while der kører alle rækker igennem
{
$usernametable = $row['username'];
}
if ($usernametable == $username)
{
die ('dette brugernavn eksitere allerede!');
exit;
}
else
{
// Reshow the form with an error
$reg_error = 'Udfyld Venligst alle felterne.';
include 'register_form.inc.php';
// Get a salt using our function
$salt = generate_salt();
// Now encrypt the password using that salt
$encrypted = md5(md5($password).$salt);
// And lastly, store the information in the database
$query = "insert into user (username, password, salt) values ('$username', '$encrypted', '$salt')";
mysql_query ($query) or die ('Could not create user.');
}
}
(hved godt koden er rodet
)
register_form.inc.php
<form action="register.php" method="post">
<b>Bruger:</b> <input type="text" size="20" maxlength="20" name="username"
<?php if (isset($_POST['username'])) { ?> value="<?php echo $_POST['username']; ?>" <?php } ?>/><br />
<b>Adgangskode:</b> <input type="password" size="20" maxlength="10" name="password" /><br />
<b>Gentag Adgangskode:</b> <input type="password" size="20" maxlength="10" name="confirmpass" /><br />
<input type="submit" name="submit" value="Register!" />
</form>
register.php
<?php
// Include init file
include 'init.php';
if (!isset($_POST['submit']))
{
// Show the form
include 'register_form.inc.php';
exit;
}
else
{
// Check if any of the fields are missing
if (empty($_POST['username']) || empty($_POST['password']) || empty($_POST['confirmpass']))
{
// Reshow the form with an error
print "Udfyld Venligst ALLE felterne tak.";
include 'register_form.inc.php';
exit;
}
// Check if the passwords match
if ($_POST['password'] != $_POST['confirmpass'])
{
// Reshow the form with an error
$reg_error = 'De to kodeord er ikke ens!';
include 'register_form.inc.php';
exit;
}
// Everything is ok, register
user_register ($_POST['username'], $_POST['password']);
echo 'Du er blevet oprette, <a href="login.php">Log ind</a>';
}
?>