I am trying to implant facebook registration on my site.
I used this tutorial: http://www.9lessons.info/2011/01/user-signup-using-facebook-data.html
When I click 'register' and it's time for the code to insert the data into the database I get this error:
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'USERNAME'@'HOST' (using password: YES) in /home/a9297472/public_html/store_user_data.php on line 44
(I censored the real username and host)
According to the error the host and username were right. Here is the process code:
<?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';
}
?>
I double checked everything. The host,username,password & db_name are the same details I use in other parts of the site and it works fine. What did I do wrong?
Thanks!
Your $password
for the db is being overwritten here:
$password = $response["registration"]["password"];
I assume you want to use the one from db_con.php ;)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.