我正在为刺客"刺客建立一个网站。游戏,目前我正在设置网站的注册。我只是在学习服务器端设置,而且我似乎在添加个人时遇到了问题。使用" register.php"到SQL数据库的凭据。当我运行网站时,register.php页面根本不会出现。你能帮我修一下register.php的代码吗?谢谢!
<?php
require_once ("Includes/simplecms-config.php");
require_once ("Includes/connectDB.php");
include("Includes/header.php");
if (isset($_POST['submit'])){
$username = $_POST['username'];
$email = $_POST['email'];
$query = "INSERT INTO users (username, password, email, key, iv_size, salt) VALUES (?, ?, ?, ?, ?, ?)";
function RandomString($length)
{
$characters = ’0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ’;
$randstring = '';
for ($i = 0; $i < $length; $i++) {
$randstring = $characters[rand(0, strlen($characters))];
}
return $randstring;
}
$code = RandomString(25);
mail($email, "Your code for the Assassin game.", "Your code is: $code");
$salt = RandomString(8);
$hashedcode = "";
for($i=0;$i<5;i++){
$hashedcode = sha1($hashedcode.$code.$salt);
}
$key = pack('H*', "bcb04b7e103a0cd8b54763051cef08bc55abe029fdebae5e1d417e2ffb2a00a3");
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$encryptedname = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $name, MCRYPT_MODE_CBC, $iv);
$encryptedemail = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $email, MCRYPT_MODE_CBC, $iv);
$encryptedname_base64 = base64_encode($encryptedname);
$encryptedemail_base64 = base64_encode($encryptedemail);
$statement = $databaseConnection->prepare($query);
$statement->bind_param('ssssssi', $encryptedname_base64, $hashedcode, $encryptedemail_base64, $key, $iv_size, $salt);
$statement->execute();
$statement->store_result();
$creationWasSuccessful = $statement->affected_rows == 1 ? true : false;
if ($creationWasSuccessful)
{
$userId = $statement->insert_id;
$addToUserRoleQuery = "INSERT INTO users_in_roles (user_id, role_id) VALUES (?, ?)";
$addUserToUserRoleStatement = $databaseConnection->prepare($addToUserRoleQuery);
$userRoleId = 2;
$addUserToUserRoleStatement->bind_param('dd', $userId, $userRoleId);
$addUserToUserRoleStatement->execute();
$addUserToUserRoleStatement->close();
$_SESSION['userid'] = $userId;
$_SESSION['username'] = $username;
header ("Location: index.php");
}
else
{
echo "Failed registration";
}
}
?>
答案 0 :(得分:0)
您在以下行的末尾缺少一个分号:
mail($email, "Your code for the Assassin game.", "Your code is: $code")//here