Php Facebook身份验证失败
一个论坛的成员为我的网站创建了一个认证系统,允许用户登录或注册 在我的网站上使用facebook api facebook sdk 不知什么原因,我一定是把系统坏了,无法连接 你能帮我解决这个问题吗 我正在使用facebook sdk php类https://github.com/facebook/facebook-php-sdk 使用的文件上载到pastebin上,因为它们太长 facebook connexion窗口正在打开,发送回来的url似乎包含身份验证所需的de信息,但没有创建facebook的cookie,不会在chrome控制台上显示 所以我认为问题一定来自config.php文件 我使用smarty作为模板引擎,如果这会影响任何东西的话 我的网站 www.entendu.info 登录url:www.entendu.info/login 非常感谢Php Facebook身份验证失败,php,facebook,smarty,facebook-php-sdk,Php,Facebook,Smarty,Facebook Php Sdk,一个论坛的成员为我的网站创建了一个认证系统,允许用户登录或注册 在我的网站上使用facebook api facebook sdk 不知什么原因,我一定是把系统坏了,无法连接 你能帮我解决这个问题吗 我正在使用facebook sdk php类https://github.com/facebook/facebook-php-sdk 使用的文件上载到pastebin上,因为它们太长 facebook connexion窗口正在打开,发送回来的url似乎包含身份验证所需的de信息,但没有创建face
<?php
require_once ($config[basedir] . '/include/facebook_api/facebook.php');
if ($config['enable_fc'] == "1") {
$facebook = new Facebook( array('appId' => '**APPID***', 'secret' => '***SECRETID***', ));
$user = $facebook -> getUser();
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook -> api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
if (isset($_SESSION['fb_277467322296156_user_id'])) {
$femail = $user_profile['email'];
$fname = $user_profile['name'];
$fname = htmlentities(strip_tags($fname), ENT_COMPAT, "UTF-8");
$femail = htmlentities(strip_tags($femail), ENT_COMPAT, "UTF-8");
$fsex = $user_profile['gender'];
$fsex = htmlentities(strip_tags($fsex), ENT_COMPAT, "UTF-8");
if ($fsex == "male") {
$ag = "1";
} else {
$ag = "0";
}
$ffirstname = $user_profile['first_name'];
$flastname = $user_profile['last_name'];
$date = explode('/', $user_profile['birthday']);
$fbirthday = $date[2] . "/" . $date[0] . "/" . $date[1];
$fcity = $user_profile['hometown']['name'];
$query = "SELECT USERID FROM members WHERE email='" . mysql_real_escape_string($femail) . "' limit 1";
$executequery = $conn -> execute($query);
$FUID = intval($executequery -> fields['USERID']);
if ($FUID > 0) {
$query = "SELECT USERID,email,username,verified,gender from members WHERE USERID='" . mysql_real_escape_string($FUID) . "' and status='1'";
$result = $conn -> execute($query);
if ($result -> recordcount() > 0) {
$query = "update members set lastlogin='" . time() . "', lip='" . $_SERVER['REMOTE_ADDR'] . "' WHERE USERID='" . mysql_real_escape_string($FUID) . "'";
$conn -> execute($query);
$_SESSION['USERID'] = $result -> fields['USERID'];
$_SESSION['EMAIL'] = $result -> fields['email'];
$_SESSION['USERNAME'] = $result -> fields['username'];
$_SESSION['VERIFIED'] = $result -> fields['verified'];
$_SESSION['GENDER'] = $result -> fields['gender'];
$_SESSION['FB'] = "1";
}
} else {
$md5pass = md5(generateCode(5) . time());
if ($fname != "" && $femail != "") {
$query = "INSERT INTO members SET email='" . mysql_real_escape_string($femail) . "',birthday='" . mysql_real_escape_string($fbirthday) . "',city='" . mysql_real_escape_string($fcity) . "',username='" . mysql_real_escape_string($fname) . "',firstname='" . mysql_real_escape_string($ffirstname) . "',lastname='" . mysql_real_escape_string($flastname) . "', password='" . mysql_real_escape_string($md5pass) . "', addtime='" . time() . "', lastlogin='" . time() . "', ip='" . $_SERVER['REMOTE_ADDR'] . "', lip='" . $_SERVER['REMOTE_ADDR'] . "', verified='1', gender='" . $ag . "'";
$result = $conn -> execute($query);
$userid = mysql_insert_id();
if ($userid != "" && is_numeric($userid) && $userid > 0) {
$query = "SELECT USERID,email,username,verified,gender from members WHERE USERID='" . mysql_real_escape_string($userid) . "'";
$result = $conn -> execute($query);
$_SESSION['USERID'] = $result -> fields['USERID'];
$_SESSION['EMAIL'] = $result -> fields['email'];
$_SESSION['USERNAME'] = $result -> fields['username'];
$_SESSION['VERIFIED'] = $result -> fields['verified'];
$_SESSION['SGENDER'] = $result -> fields['gender'];
$_SESSION['FB'] = "1";
$url = "http://graph.facebook.com/$user/picture?type=large";
$sourceFilePath = CurlHelper::downloadFile($url, array('followLocation' => true, 'maxRedirs' => 5, ));
$theimageinfo = getimagesize($sourceFilePath);
$thepp = $_SESSION['USERID'];
if ($theimageinfo[2] == 1) {
$thepp .= ".gif";
} elseif ($theimageinfo[2] == 2) {
$thepp .= ".jpg";
} elseif ($theimageinfo[2] == 3) {
$thepp .= ".png";
}
$myvideoimgnew = $config['membersprofilepicdir'] . "/" . $thepp;
$thumb = PhpThumbFactory::create($sourceFilePath);
//on save tel quel
$thumb -> save($myvideoimgnew);
//on redimensionne la photo
$thumb -> resize(100, 100);
// save dans le bon rep
$tothumbdir = $config['membersprofilepicdir'] . "/thumbs/" . $thepp;
$thumb -> save($tothumbdir);
if (file_exists($config['membersprofilepicdir'] . "/" . $thepp)) {
$query = "UPDATE members SET profilepicture='$thepp' WHERE USERID='" . mysql_real_escape_string($_SESSION['USERID']) . "'";
$conn -> execute($query);
} else {
$error = "$lang[135]";
}
}
}
}
} else {
$facebook = new Facebook( array('appId' => '**APPID**', 'secret' => '**SECRETID**', ));
$params = array(scope => 'email, user_birthday');
$loginUrl = $facebook -> getLoginUrl($params);
if ($_SESSION['language'] == "english") {
$loginLien_right = "<a href='$loginUrl'><img id='fb_login_image' src='$config[imageurl]/fb_signup_en_right.png' alt='Login Facebook'/></a>";
$loginLien = "<a href='$loginUrl'><img id='fb_login_image' src='$config[imageurl]/fb_signup_en.png' alt='Login Facebook'/></a>";
} else {
$loginLien_right = "<a href='$loginUrl'><img id='fb_login_image' src='$config[imageurl]/fb_signup_fr_right.png' alt='Login Facebook'/></a>";
$loginLien = "<a href='$loginUrl'><img id='fb_login_image' src='$config[imageurl]/fb_signup_fr.png' alt='Login Facebook'/></a>";
}
STemplate::assign('loginFB', $loginLien);
STemplate::assign('loginFBright', $loginLien_right);
}
}
?>
由于我没有10个或更多的声誉,我不能发布超过2个超链接,所以我加入了他们的一个粘贴站链接
非常感谢如果ifisset$\u COOKIE['fbsr\u 277467322296156'],我需要用ifisset$\u COOKIE['fbsr\u 277467322296156']替换ifisset$\u会话['fbsr\u 272296156'],我不确定您的实际问题是什么。你是说如果你用Facebook登录,然后返回应用程序,你看不到任何用户信息吗?没错。。。用户未登录。。。。
<?php
require_once ($config[basedir] . '/include/facebook_api/facebook.php');
if ($config['enable_fc'] == "1") {
$facebook = new Facebook( array('appId' => '**APPID***', 'secret' => '***SECRETID***', ));
$user = $facebook -> getUser();
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook -> api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
if (isset($_SESSION['fb_277467322296156_user_id'])) {
$femail = $user_profile['email'];
$fname = $user_profile['name'];
$fname = htmlentities(strip_tags($fname), ENT_COMPAT, "UTF-8");
$femail = htmlentities(strip_tags($femail), ENT_COMPAT, "UTF-8");
$fsex = $user_profile['gender'];
$fsex = htmlentities(strip_tags($fsex), ENT_COMPAT, "UTF-8");
if ($fsex == "male") {
$ag = "1";
} else {
$ag = "0";
}
$ffirstname = $user_profile['first_name'];
$flastname = $user_profile['last_name'];
$date = explode('/', $user_profile['birthday']);
$fbirthday = $date[2] . "/" . $date[0] . "/" . $date[1];
$fcity = $user_profile['hometown']['name'];
$query = "SELECT USERID FROM members WHERE email='" . mysql_real_escape_string($femail) . "' limit 1";
$executequery = $conn -> execute($query);
$FUID = intval($executequery -> fields['USERID']);
if ($FUID > 0) {
$query = "SELECT USERID,email,username,verified,gender from members WHERE USERID='" . mysql_real_escape_string($FUID) . "' and status='1'";
$result = $conn -> execute($query);
if ($result -> recordcount() > 0) {
$query = "update members set lastlogin='" . time() . "', lip='" . $_SERVER['REMOTE_ADDR'] . "' WHERE USERID='" . mysql_real_escape_string($FUID) . "'";
$conn -> execute($query);
$_SESSION['USERID'] = $result -> fields['USERID'];
$_SESSION['EMAIL'] = $result -> fields['email'];
$_SESSION['USERNAME'] = $result -> fields['username'];
$_SESSION['VERIFIED'] = $result -> fields['verified'];
$_SESSION['GENDER'] = $result -> fields['gender'];
$_SESSION['FB'] = "1";
}
} else {
$md5pass = md5(generateCode(5) . time());
if ($fname != "" && $femail != "") {
$query = "INSERT INTO members SET email='" . mysql_real_escape_string($femail) . "',birthday='" . mysql_real_escape_string($fbirthday) . "',city='" . mysql_real_escape_string($fcity) . "',username='" . mysql_real_escape_string($fname) . "',firstname='" . mysql_real_escape_string($ffirstname) . "',lastname='" . mysql_real_escape_string($flastname) . "', password='" . mysql_real_escape_string($md5pass) . "', addtime='" . time() . "', lastlogin='" . time() . "', ip='" . $_SERVER['REMOTE_ADDR'] . "', lip='" . $_SERVER['REMOTE_ADDR'] . "', verified='1', gender='" . $ag . "'";
$result = $conn -> execute($query);
$userid = mysql_insert_id();
if ($userid != "" && is_numeric($userid) && $userid > 0) {
$query = "SELECT USERID,email,username,verified,gender from members WHERE USERID='" . mysql_real_escape_string($userid) . "'";
$result = $conn -> execute($query);
$_SESSION['USERID'] = $result -> fields['USERID'];
$_SESSION['EMAIL'] = $result -> fields['email'];
$_SESSION['USERNAME'] = $result -> fields['username'];
$_SESSION['VERIFIED'] = $result -> fields['verified'];
$_SESSION['SGENDER'] = $result -> fields['gender'];
$_SESSION['FB'] = "1";
$url = "http://graph.facebook.com/$user/picture?type=large";
$sourceFilePath = CurlHelper::downloadFile($url, array('followLocation' => true, 'maxRedirs' => 5, ));
$theimageinfo = getimagesize($sourceFilePath);
$thepp = $_SESSION['USERID'];
if ($theimageinfo[2] == 1) {
$thepp .= ".gif";
} elseif ($theimageinfo[2] == 2) {
$thepp .= ".jpg";
} elseif ($theimageinfo[2] == 3) {
$thepp .= ".png";
}
$myvideoimgnew = $config['membersprofilepicdir'] . "/" . $thepp;
$thumb = PhpThumbFactory::create($sourceFilePath);
//on save tel quel
$thumb -> save($myvideoimgnew);
//on redimensionne la photo
$thumb -> resize(100, 100);
// save dans le bon rep
$tothumbdir = $config['membersprofilepicdir'] . "/thumbs/" . $thepp;
$thumb -> save($tothumbdir);
if (file_exists($config['membersprofilepicdir'] . "/" . $thepp)) {
$query = "UPDATE members SET profilepicture='$thepp' WHERE USERID='" . mysql_real_escape_string($_SESSION['USERID']) . "'";
$conn -> execute($query);
} else {
$error = "$lang[135]";
}
}
}
}
} else {
$facebook = new Facebook( array('appId' => '**APPID**', 'secret' => '**SECRETID**', ));
$params = array(scope => 'email, user_birthday');
$loginUrl = $facebook -> getLoginUrl($params);
if ($_SESSION['language'] == "english") {
$loginLien_right = "<a href='$loginUrl'><img id='fb_login_image' src='$config[imageurl]/fb_signup_en_right.png' alt='Login Facebook'/></a>";
$loginLien = "<a href='$loginUrl'><img id='fb_login_image' src='$config[imageurl]/fb_signup_en.png' alt='Login Facebook'/></a>";
} else {
$loginLien_right = "<a href='$loginUrl'><img id='fb_login_image' src='$config[imageurl]/fb_signup_fr_right.png' alt='Login Facebook'/></a>";
$loginLien = "<a href='$loginUrl'><img id='fb_login_image' src='$config[imageurl]/fb_signup_fr.png' alt='Login Facebook'/></a>";
}
STemplate::assign('loginFB', $loginLien);
STemplate::assign('loginFBright', $loginLien_right);
}
}
?>