• 16-06-2016, 14:39:54
    #1
    Scriptte facebook ile login olmaya çalıştığımda aldığım hata aşağıdaki gibidir.
    Warning: PDOStatement::execute(): SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'mail' cannot be null in /home3/zuhurat/public_html/modules/session/fb_login.php on line 135
    
    Warning: Cannot modify header information - headers already sent by (output started at /home3/zuhurat/public_html/modules/session/fb_login.php:135) in /home3/zuhurat/public_html/modules/session/fb_login.php on line 154
    fb_login.php dosyam iste aşağıdaki gibidir.
    <?php
    
    session_start();
    
    require_once app_base_path('/thirdparty/Facebook/FacebookSession.php');
    require_once app_base_path('/thirdparty/Facebook/FacebookRedirectLoginHelper.php');
    require_once app_base_path('/thirdparty/Facebook/FacebookCanvasLoginHelper.php');
    require_once app_base_path('/thirdparty/Facebook/FacebookJavaScriptLoginHelper.php');
    require_once app_base_path('/thirdparty/Facebook/FacebookRequest.php');
    require_once app_base_path('/thirdparty/Facebook/FacebookResponse.php');
    require_once app_base_path('/thirdparty/Facebook/FacebookSDKException.php');
    require_once app_base_path('/thirdparty/Facebook/FacebookRequestException.php');
    require_once app_base_path('/thirdparty/Facebook/FacebookAuthorizationException.php');
    require_once app_base_path('/thirdparty/Facebook/GraphObject.php');
    require_once app_base_path('/thirdparty/Facebook/HttpClients/FacebookCurl.php');
    require_once app_base_path('/thirdparty/Facebook/HttpClients/FacebookHttpable.php');
    require_once app_base_path('/thirdparty/Facebook/HttpClients/FacebookCurlHttpClient.php');
    require_once app_base_path('/thirdparty/Facebook/GraphUser.php');
    
    use Facebook\FacebookSession;
    use Facebook\FacebookRedirectLoginHelper;
    use Facebook\FacebookCanvasLoginHelper;
    use Facebook\FacebookJavaScriptLoginHelper;
    use Facebook\FacebookRequest;
    use Facebook\FacebookResponse;
    use Facebook\FacebookSDKException;
    use Facebook\FacebookRequestException;
    use Facebook\FacebookAuthorizationException;
    use Facebook\GraphObject;
    use Facebook\HttpClients\FacebookCurl;
    use Facebook\HttpClients\FacebookHttpable;
    use Facebook\HttpClients\FacebookCurlHttpClient;
    use Facebook\GraphUser;
    
    Facebook\FacebookSession::setDefaultApplication('1699101090323930','97727af42e8d6df6197e2d8cb6c28f10');
    $helper = new Facebook\FacebookRedirectLoginHelper(full_uri('fb-login'));
    
    if (isset($_REQUEST['code'])) {
        try {
            $session = $helper->getSessionFromRedirect();
        } catch(FacebookRequestException $ex) {
            
        } catch(\Exception $ex) {
            
        }
    
        if (isset($session)) {
            if (!$session) {
                header('Location: '.full_uri('main'));
                exit;
            }
            
            $fb_user = (new FacebookRequest(
                $session, 'GET', '/me'
            ))->execute()->getGraphObject(GraphUser::className())->asArray();
            
            $fb_avatar_url = (new FacebookRequest(
                $session, 'GET', '/me/picture?redirect=false&width=150&height=150'
            ))->execute()->getGraphObject(GraphUser::className())->asArray()['url'];
            
            global $database;
            connect_database();
            
            ob_start();
            ?>
            select
                *
            from
                users
            where
                mail = ?
            <?php
            $query = ob_get_clean();
            $query = $database->prepare($query);
            $query->execute(array($fb_user['email']));
            $user_from_fb = $query->fetch();
            
            if (!$user_from_fb) {
                $user_uniqid = uniqid();
                if ($fb_avatar_url) {
                    $avatar_file_name = $user_uniqid.'.jpg';
                    file_put_contents(
                        static_path('/images/'.$avatar_file_name),
                        file_get_contents($fb_avatar_url)
                    );
                } else {
                    $avatar_file_name = '';
                }
    
                ob_start();
                ?>
                insert
                    into
                        users
                    (
                        namespace,
                        fb_id,
                        mail,
                        user_name,
                        avatar,
                        password,
                        name,
                        `source`,
                        added_time,
                        updated_time,
                        record_order
                    )
                    values (
                        :namespace,
                        :fb_id,
                        :mail,
                        :user_name,
                        :avatar,
                        :password,
                        :name,
                        <?php echo USER_SOURCE_FACEBOOK; ?>,
                        NOW(),
                        NOW(),
                        <?php echo time(); ?>
                    )
                <?php
                $query = ob_get_clean();
                $query = $database->prepare($query);
    
                $user_name = 'yazar'.$user_uniqid;
                $user_namespace = sef_url($user_name);
    
                $query->bindParam(':namespace', $user_namespace, PDO::PARAM_STR);
                $query->bindParam(':fb_id', $fb_user['id'], PDO::PARAM_STR);
                $query->bindParam(':mail', $fb_user['email'], PDO::PARAM_STR);
                $query->bindParam(':user_name', $user_name, PDO::PARAM_STR);
                $query->bindParam(':avatar', $avatar_file_name, PDO::PARAM_STR);
                $query->bindValue(':password', '', PDO::PARAM_STR);
                $query->bindParam(':name', $fb_user['name'], PDO::PARAM_STR);
                $query->execute();
    
                $_SESSION[SESSION_INDEX]['user'] = array(
                    'id'=>$database->lastInsertId(),
                    'fb_id'=>$fb_user['id'],
                    'namespace'=>$user_namespace,
                    'mail'=>$fb_user['email'],
                    'user_name'=>$user_name,
                    'avatar'=>$avatar_file_name,
                    'name'=>$fb_user['name'],
                    'source'=>USER_SOURCE_FACEBOOK,
                    'count_news'=>0,
                    'count_news_accepted'=>0,
                    'count_news_rejected'=>0,
                    'count_news_waiting'=>0,
                    'count_comments'=>0,
                    'count_comments_accepted'=>0,
                );
                
                header('Location: '.full_uri('main'));
            } else {
                $_SESSION[SESSION_INDEX]['user'] = $user_from_fb;
                header('Location: '.full_uri('main'));
            }
        } else {
            header('Location: '.full_uri('main'));
        }
    } else{
        $fb_login_url = $helper->getLoginUrl(array('email'));
        header('Location: '.$fb_login_url);
    }
    
    ?>

    Hata nerededir acaba ? Kodlamada pek anlamadığım için sıkıntıyı bulamadım yardımcı olursanız sevinirim.
  • 16-06-2016, 18:08:24
    #2
    Merhaba,

    Sorunda sizin veritabanınızdaki "mail" field i null olamaz diyor yani pdo ile execute ettiğinde mail alanın boş gidiyor demektir.

    $fb_user['email'] alanı boş geliyor yani veride , öncelikle scope ları kontrol edin email alanı var mı? Yani izin olarak email alanını istiyor musunuz.

    2. satır sorunda zaten basılan hata start tan önce basıldığı için header mesajı alıyorsunuz.