Facebook身份验证失败

时间:2012-05-02 21:38:19

标签: php facebook smarty facebook-php-sdk

论坛成员为我的网站创建了一个身份验证系统,允许用户登录或注册 在我的网站上使用facebook api(facebook sdk)

由于一个不明原因(我必须搞砸了),系统停止工作,我无法连接。

你能帮我解决问题。

我正在使用facebook-sdk php类(https://github.com/facebook/facebook-php-sdk) (使用的文件在pastebin上传,因为它们太长了)

facebook连接窗口是oppening,发回的网址似乎包含验证所需的信息(但没有创建facebook的cookie(不在chrome控制台上显示))

所以我认为问题必须来自config.php文件 如果这会影响任何事情,我会使用smarty作为模板引擎。

我的网站 www.entendu.info

登录网址:www.entendu.info/login

非常感谢

<?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个超链接,所以我加入了一个pastebin链接

http://pastebin.com/02cm3DjZ

非常感谢

0 个答案:

没有答案