Fatal Error: can't redeclare hash
Posted: Fri Mar 02, 2012 8:15 pm
Hi folks! I've been trying to get a decent working login, and of course this includes a register portion. It seems to work fine, however after I register, it says Fatal Error: Cannot redeclare hash() and no information is processed.
I know the hash function already comes with php so I shouldn't redeclare it like I am, but I'm a bit confused on how would I create a salt/hash without declaring it? Here's the entire register script I have, the salts and hashes I added for (supposedly, from my readings anyway) better security.
I know the hash function already comes with php so I shouldn't redeclare it like I am, but I'm a bit confused on how would I create a salt/hash without declaring it? Here's the entire register script I have, the salts and hashes I added for (supposedly, from my readings anyway) better security.
Code: Select all
include('config.php');
if($loggedin == '1')
die('You can't register another account while you're logged in.');
if(isset($_POST['submit']))
{
$uname = trim($_POST['username']);
function hash($pass) {
$hash = hash('sha256', $pass);
function createSalt()
{
$string = md5(uniqid(rand(), true));
return substr($string, 0, 3);
}
$salt = createSalt();
$hash = hash('sha256', $salt . $hash);
$uname = mysql_real_escape_string($uname);
}
if((!isset($_POST['username'])) || (!isset($_POST['pass']))
|| ($uname == '') || ($_POST['pass'] == ''))
die("Please fill out the form completely. <br><br>
<a href=register.php>Continue</a>");
$check = @mysql_query("SELECT id FROM players WHERE username = '$uname'");
$check = @mysql_num_rows($check);
if($check > 0)
die("Sorry, that username has already been taken. Please try again.
<br><br>
<a href=register.php>Continue</a>");
$pass = md5($_POST['pass']);
$newPlayer = @mysql_query("INSERT INTO players (username, password, registered) VALUES ('$username','$hash','$salt')") or die("Error: ".mysql_error());
echo 'You have been registered! You may now <a href=index.php>Log in</a>.';
}
else
{
echo '<form action=register.php method=post>
Username: <input type=text name=username><br>
Password: <input type=password name=pass><br>
<input type=submit name=submit value=Submit>
</form>';
}