Updade:
Ok so I've fixed my previous problem (Besides the SQLinjection which I'm not sure how to patch but for now it's unimportant) however I need to get it to detect Male or Female and strip some characters from it too... This is the code I did for that
I defined the variable here:
$gender = $response["registration"]["gender"];
I then defined newgender here
$new_gender = "F";
However I then added an if statement which was supposed to detect if it was Male and change it to "M"
if($gender == "Male"){
$new_gender = "M";
}
The code seems to be simply ignoring the if statement as it always renders as a F for female. (I need the code this way or a similar alternative because the way the sql database works it needs to be 1 letter long so M or F only.
My second problem is having the registered time show up in the DB but if someone can solve this problem first I'll update it with my other issue.
Many thanks,
Brad
I've been trying to make it so when a user clicks register with facebook it adds there information into my database. I'm getting an error however so not sure what to do... Here's the code, please help me in any way you can.
<?php
define('FACEBOOK_APP_ID', '276105599128518');
define('FACEBOOK_SECRET', 'mysecretappidhere');
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) {
echo '<p>signed_request contents:</p>';
$response = parse_signed_request($_REQUEST['signed_request'],
FACEBOOK_SECRET);
//$no_longer_needed_but_save_for_backup = explode(' ',$name,2);
//$dunno = $name_arr[0];
//$dunno = isset($name_arr[1])?$name_arr[1]:'';
//$Location_Array = $response["registration"]["location"]["name"];
$uname = $response["registration"]["username"];
$rname = $response["registration"]["name"];
$seckey = $response["registration"]["seckey"];
$email = $response["registration"]["email"];
$password = $response["registration"]["password"];
$gender = $response["registration"]["gender"];
$ip_last = $_SERVER['REMOTE_ADDR'];
$sessionKey = 'RevCMS-'.rand(9,999).'/'.substr(sha1(time()).'/'.rand(9,9999999).'/'.rand(9,9999999).'/'.rand(9,9999999),0,33);
// Connecting to database
mysql_connect('localhost', 'root', 'mypasswouldbehere') or die("MySQL Error: " . mysql_error());
mysql_select_db('phoenix3') or die("MySQL Error: " . mysql_error());
// Inserting into users table
$result = mysql_query("INSERT INTO users (id, username, real_name, password, mail, auth_ticket, rank, credits, vip_points, activity_points, activity_points_lastupdate, look, gender, motto, acount_created, last_online, online, ip_last, ip_reg, home_room, respect, daily_respect_points, daily_pet_respect_points, newbie_status, is_muted, mutant_penalty, mutant_penalty_expire, block_newfriends, hide_online, hide_inroom, mail_verified, vip, volume, seckey)
VALUES
(NULL, '$uname', '$rname', '$password', '$email', '$sessionKey','8', '10000', '0', '0', '0', '-', '$gender', 'I <3 Tropical-Resort', 'time()', ' . time() . ', '0', '$ip_last', '$ip_last', '8', '0', '3', '3', '0', '0', '0', '0', '0', '0', '0', '1', '0', '100', '$seckey')");
if($result){
echo"should/'ve stored";
// GOT RESULTS
}
else
{
echo "error";
// Error in storing
}
}
else
{
echo '$_REQUEST is empty';
}
?>
Yours, Brad
ceejayoz fixed the issue, echoing
echo mysql_error();
solves the issue as it tells you ALL the mysql problems you have. To fix the gender issue which was I needed to shorten it from Male to "M" or Female to "F" just use PHP's substr so example is...Thanks everyone who helped, -Brad