ユーザーのログイン確認スクリプトを作成しようとしています。次のコードである checklogin.php と呼ばれる 2 つのページがあります。
<?php
session_start();
$host="localhost"; // Host name
$username="root"; // Mysql username
$password="testdbpass"; // Mysql password
$db_name="test"; // Database name
$table = "users";
// Connect to server via PHP Data Object
$db = new PDO("mysql:host=localhost;dbname=test;", $username, $password);
$username = $_POST['username'];
$password = $_POST['password'];
if(isset($_POST['username']) && !empty($_POST['username'])
AND
isset($_POST['password']) && !empty($_POST['password']))
$pass = crypt($password . $row['salt']);
$statement->bindParam(':username', $username);
$query = ("SELECT * FROM $table WHERE username = :username");
$statement = $db->prepare($query);
$output = 'Login Error';
if ($statement->execute() && $row = $statement->fetch())
{
if ($row['password'] === $pass)
{
if ( $row['activated'] !== 0 ) {
$output = 'Not activiated wait for Administrator Approval';
$_SESSION['username'] = $username;
}
$output = 'Logged In';
}
}
echo $output;
$db = null;
?>
そして、私はこのコードである register_script.php ページを持っています:
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password="testdbpass"; // Mysql password
$db_name="test"; // Database name
// Connect to server via PHP Data Object
$dbh = new PDO("mysql:host=localhost;dbname=test;", $username, $password);
CRYPT_BLOWFISH or die ('No Blowfish found.');
//This string tells crypt to use blowfish for 15 rounds.
$Blowfish_Pre = '$2y$15$';
$Blowfish_End = '$';
// Blowfish accepts these characters for salts.
$Allowed_Chars =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789./';
$Chars_Len = 63;
$Salt_Length = 45;
$salt = "";
for($x=0;$x<5000;$x++)
{
$salt .= $Allowed_Chars[mt_rand(0,$Chars_Len)];
}
$bcrypt_salt = $Blowfish_Pre . $salt . $Blowfish_End;
$password = $_POST['password'];
$hashed_password = crypt($password, $bcrypt_salt);
// Insert statements with PDO
try {
$query = $dbh->prepare("INSERT INTO `users_blowfish` (username, email, fname, lname, salt, password)
VALUES (:username, :email, :first, :last, :salt, :hash)");
$params = array(
'username' => $_POST['username'],
'email' => $_POST['email'],
'first' => $_POST['fname'],
'last' => $_POST['lname'],
'salt' => $bcrypt_salt,
'hash' => $hashed_password);
$query->execute($params);
}
catch (PDOException $e) {
error_log($e->getMessage());
die("An error occured, contact admin");
}
$dbh= null;
?>
<html>
<body>
<p>
Thank you for registering your account. Please wait for administrator approval before doing anything else. Thank you - System Administrator.
</p>
</body>
</html>
ログインしようとすると、apache2 エラー ファイルの状態でエラー ログが表示されます。
[2012 年 12 月 22 日土曜日 11:47:36] [エラー] [クライアント デスクトップ] PHP 解析エラー: 構文エラー、23 行目の /var/www/version2/checklogin.php の予期しない T_VARIABLE、リファラー: * http://localhost/version2/
*
これで問題を特定できないようです。PDOの操作方法についてphp.netを参照しましたが、役に立ちませんでした。register_script.php が正常に動作しているため、問題は checklogin.php によって引き起こされています (数日前からテスト済み)。どんな助けでも素敵ですありがとう。
編集1:
行 23 は次のように進みます。$statement->bindParam(':username', $username);
編集2:問題を引き起こしている可能性のある行:
`$pass = crypt($password . $row['salt']);
$statement->bindParam(':username', $username);
$query = ("SELECT * FROM $table WHERE username = :username");
$statement = $db->prepare($query);
$output = 'Login Error';`