MySQL:"拒绝访问"

Asa*_*ton 1 php mysql facebook registration

我想在我的网站上植入facebook注册.

我使用了本教程:http://www.9lessons.info/2011/01/user-signup-using-facebook-data.html

当我单击"注册"并且代码将数据插入数据库时​​,我收到此错误:

警告:mysql_connect()[function.mysql-connect]:第44行/home/a9297472/public_html/store_user_data.php中用户"USERNAME"@"HOST"(使用密码:YES)拒绝访问

(我审查了真实的用户名和主持人)

根据错误,主机和用户名是正确的.这是流程代码:

<?php
include('config/db_con.php');
define('FACEBOOK_APP_ID', 'APP ID'); // Place your App Id here
define('FACEBOOK_SECRET', 'APP SECRET'); // Place your App Secret Here

// No need to change the function body
function parse_signed_request($signed_request, $secret) 
{
    list($encoded_sig, $payload) = explode('.', $signed_request, 2);
    // decode the data
    $sig = base64_url_decode($encoded_sig);
    $data = json_decode(base64_url_decode($payload), true);
    if (strtoupper($data['algorithm']) !== 'HMAC-SHA256')
    {
        error_log('Unknown algorithm. Expected HMAC-SHA256');
        return null;
    }

    // check sig
    $expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
    if ($sig !== $expected_sig) 
    {
        error_log('Bad Signed JSON signature!');
        return null;
    }
    return $data;
}
function base64_url_decode($input) 
{
    return base64_decode(strtr($input, '-_', '+/'));
}
if ($_REQUEST) 
{
    $response = parse_signed_request(
        $_REQUEST['signed_request'],
        FACEBOOK_SECRET
    );

    $name = $response["registration"]["name"];
    $email = $response["registration"]["email"];
    $password = $response["registration"]["password"];
    $gender = $response["registration"]["gender"];
    $dob = $response["registration"]["birthday"];

    // Connecting to database
    mysql_connect("$host", "$username", "$password")or die("cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");

    // Inserting into users table
    $result = mysql_query("
INSERT INTO users (
    name, email, password, gender, dob
) VALUES (
    '$name', '$email', '$password', '$gender', '$dob')
");

    if($result){
    // User successfully stored
    }
    else
    {
        // Error in storing
    }
}
else 
{
    echo '$_REQUEST is empty';
}

?>
Run Code Online (Sandbox Code Playgroud)

我仔细检查了一切.主机,用户名,密码和db_name与我在网站的其他部分使用的细节相同,并且工作正常.我做错了什么?

谢谢!

Qua*_*unk 5

$password的数据库被覆盖了:

$password = $response["registration"]["password"];

我假设您要使用db_con.php中的那个;)

  • 好抓!另一个提示:将您的数据库凭据声明为常量,这样您就不会在脚本中实际覆盖它们. (2认同)