Ich habe auf meiner Homepage eine Register mit diesem Code hier.
Code:
<?php
if( isset( $_POST['username'] ) && !empty( $_POST['username'] ) && isset( $_POST['password'] ) && !empty( $_POST['password'] ))
{
$conf['db']['server'] = '123.456.789.123';
$conf['db']['user'] = 'mysql_username_here';
$conf['db']['pass'] = 'mysql_assword_here';
$conf['dbname']['auth'] = 'newproject_auth';
$salt = 'salt_here';
// Create the DSN
$conf['db']['dsn'] = sprintf("mysql:host=%s;dbname=%s", $conf['db']['server'], $conf['dbname']['auth'] );
// Try to connect to the database
try
{
$db = new PDO($conf['db']['dsn'], $conf['db']['user'], $conf['db']['pass']);
}
catch(PDOException $e)
{
die('Error connecting to the database<br />');
}
$dbh = $db->prepare("SELECT count(*) FROM bg_user WHERE user_id = :user");
$dbh->execute( array( ':user' => $_POST['username'] ));
$result = $dbh->fetch();
if( $result[0] != 0 )
echo 'User '. htmlspecialchars( $_POST['username'] ) .' already exist';
else
{
$hash = hash('sha256', $_POST['username'] . $salt . $_POST['password']);
$dbh = $db->prepare("INSERT INTO bg_user (user_id, passwd) VALUES(:user,:pass)");
$dbh->execute( array( ':user' => $_POST['username'],
':pass' => $hash ));
echo '['. htmlspecialchars( $_POST['username'] ) .'] Deine Registrierung war erfolgreich, du kannst dich nun Einloggen im Spiel.<hr />';
}
}
else
{
echo '
<form method="post">
<table>
<tr>
<td>Username</td>
<td><input type="text" name="username" size="30" maxlength="16" /></td>
</tr>
<tr>
<td>Password</td>
<td><input type="text" name="password" size="30" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Create account" /></td>
</tr>
</table>
</form>';
}
?>
Ich nutze derzeit PHP-Fusion V7.02 ich habe mit diesem Code eine Datei erstellt. game_register.php dies eingetragen.
Code:
<?php
if( isset( $_POST['username'] ) && !empty( $_POST['username'] ) && isset( $_POST['password'] ) && !empty( $_POST['password'] ))
{
$conf['db']['server'] = '123.456.789.123';
$conf['db']['user'] = 'mysql_username_here';
$conf['db']['pass'] = 'mysql_assword_here';
$conf['dbname']['auth'] = 'newproject_auth';
$salt = 'salt_here';
// Create the DSN
$conf['db']['dsn'] = sprintf("mysql:host=%s;dbname=%s", $conf['db']['server'], $conf['dbname']['auth'] );
// Try to connect to the database
try
{
$db = new PDO($conf['db']['dsn'], $conf['db']['user'], $conf['db']['pass']);
}
catch(PDOException $e)
{
die('Error connecting to the database<br />');
}
$dbh = $db->prepare("SELECT count(*) FROM bg_user WHERE user_id = :user");
$dbh->execute( array( ':user' => $_POST['username'] ));
$result = $dbh->fetch();
if( $result[0] != 0 )
echo 'User '. htmlspecialchars( $_POST['username'] ) .' already exist';
else
{
$hash = hash('sha256', $_POST['username'] . $salt . $_POST['password']);
$dbh = $db->prepare("INSERT INTO bg_user (user_id, passwd) VALUES(:user,:pass)");
$dbh->execute( array( ':user' => $_POST['username'],
':pass' => $hash ));
echo '['. htmlspecialchars( $_POST['username'] ) .'] Deine Registrierung war erfolgreich, du kannst dich nun Einloggen im Spiel.<hr />';
}
}
else
{
echo '
<form method="post">
<table>
<tr>
<td>Username</td>
<td><input type="text" name="username" size="30" maxlength="16" /></td>
</tr>
<tr>
<td>Password</td>
<td><input type="text" name="password" size="30" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Create account" /></td>
</tr>
</table>
</form>';
}
?>
LG






