我尝试使用Facebook注册插件存储相同的数据。到目前为止它的效果非常好。这是我使用的代码:
<div id="fb-root"></div>
<script src="https://connect.facebook.net/de_DE/all.js"></script>
<script>
FB.init({
appId:'23xxxxxxxxxx48',
cookie:true,
status:true,
xfbml:true
});
</script>
<fb:registration
fields="[{'name':'name'}, {'name':'email'}, {'name':'location'}, {'name':'birthday'}, {'name':'agb', 'description':'Ich bin mit den AGB´s einverstanden', 'type':'checkbox'}]"
redirect-uri="https://www.myserver.de/fbapp2-0/fbregconfirm.php"
width="510">
</fb:registration>
</div>
这是fbregconfirm.php
:
define('FACEBOOK_APP_ID', '23xxxxxxx48');
define('FACEBOOK_SECRET', 'f6xxxxxxxf0');
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 signature
$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"];
$name_arr = explode(' ',$name,2); $vname = $name_arr[0]; $zname = isset($name_arr[1])?$name_arr[1]:'';
$email =$response["registration"]["email"];
$ort = $response["registration"]["location"]["name"];
$ort_arr = explode(' ',$ort,2); $ort1 = $ort_arr[0]; $ort2 = isset($ort_arr[1])?$ort_arr[1]:'';
$anrede = $response["registration"]["gender"];
$geburtstag = $response["registration"]["birthday"];
}
// Connecting to database
mysql_connect($dbhost, $dbuser, $dbpass) or die("MySQL Error: " . mysql_error());
mysql_select_db($dbname) or die("MySQL Error: " . mysql_error());
// Inserting into users table
$vname = mysql_real_escape_string($vname);
$zname = mysql_real_escape_string($zname);
$ort1 = mysql_real_escape_string($ort1);
$email = mysql_real_escape_string($email);
$user_fbid = mysql_real_escape_string($user_fbid);
$geburtstag = date("Y-m-d" , strtotime($geburtstag));
$result = mysql_query("INSERT INTO member (mem_id, anrede, vname, zname, plz, ort, land_id, email, userpass, regdatum, regip, lastlogin, agbok, free, memkey, letter, nameindex, memoptionen, memstatus, regok, geburtstag, notizen, partner_id, fbuid)
VALUES (NULL, '".$anrede."', '".$vname."', '".$zname."', '".$plz."', '".$ort1."', '"$ort2"', '".$email."', MD5('".$pwrand."'),NOW(),'".$user_ip."', '0000-00-00 00:00:00', '1','1', '','".$letter."','".$nameindex."','', '2', '1','".$geburtstag."', '".$formkeys['datenfeld']."', '1', '".$response["user_id"]."')")};
但现在我想存储相同的额外数据,例如
$user_ip = get_uip();
$pwrand = multirandom(1, 8, 14, '');
每次我尝试包含此代码或类似代码时,都会显示http500错误。如何包含这些额外数据并将其存储在MySQL中?
答案 0 :(得分:0)
答案很简单。我忘了包含另一个PHP文件,我在其中管理所有全局信息,并定义了其他几个变量,如$user_ip
和$pwrand
。