Question

I have an application on facebook page tab that uses the getUser so that I can get the facebook id of that user it works fin on both Chrome and Firefox but not on IE. I tried to clear cache several times! here is what I am doing (this is codeigniter framework)

<?php
if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Register extends CI_Controller {

    function __construct() {
        parent::__construct();

        $this->load->library('facebook', $this->config->item('fb_config'));
        $this->load->library('Form_validation');
        $this->load->library('session');
        $this->load->model('users_model', 'users');
    }
public function index() {
   $user_id = $this->facebook->getUser();


            if ($user_id) {

                    // We have a user ID, so probably a logged in user.
                // If not, we'll get an exception, which we handle below.
                try {

                    $user_profile = $this->facebook->api('/me', 'GET');


                    $data['fb_id'] = $user_profile['id'];

                        $this->session->set_userdata('fb_id', $data['fb_id']);

                    $users = $this->users->get_by_fb_id_register($data['fb_id'], array('full_name', 'age', 'email', 'phone_number'));
                    // not first time
                    if ($users != 0 && $users->num_rows() < 1) {
                            $data['full_name'] = $user_profile['name'];
                        $birthDate = explode("/", $user_profile['birthday']);
                        $age = (date("md", date("U", mktime(0, 0, 0, $birthDate[0], $birthDate[1], $birthDate[2]))) > date("md") ? ((date("Y") - $birthDate[2]) - 1) : (date("Y") - $birthDate[2]));
                        $data['age'] = $age;
                        $data['email'] = $user_profile['email'];
                    } else {
                        $data = $users->row_array();
                    }
                } catch (FacebookApiException $e) {
                    // If the user is logged out, you can have a
                    // user ID even though the access token is invalid.
                    // In this case, we'll get an exception, so we'll
                    // just ask the user to login again here.

                    $login_url = $this->facebook->getLoginUrl(
                            array(
                                'scope' => 'email, user_birthday, publish_actions, publish_stream', //read_stream, friends_likes, user_likes
                           // 'redirect_uri' => $this->config->item('fan_page_app_link'), //the url to go to after a successful login
                    ));
                    echo '<script> window.top.location.href = "' . $login_url . '"; </script>';
                    exit;
                }
            } else {

                // No user, print a link for the user to login
                $login_url = $this->facebook->getLoginUrl(
                        array(
                            'scope' => 'email, user_birthday, publish_actions, publish_stream', //read_stream, friends_likes, user_likes
                        'redirect_uri' => $this->config->item('fan_page_app_link'), //the url to go to after a successful login
                ));
                echo '<script> window.top.location.href = "' . $login_url . '"; </script>';
                exit;
            }
}
?>

the url that gives error 500:

https://www.facebook.com/dialog/oauth?client_id=1397280120532513&redirect_uri=https%3A%2F%2FMYWEBSITE.com%2Fmatchgame%2Fregister&state=bc353f470176d5a62995722808e3f406&sdk=php-sdk-3.2.3&scope=email%2C+user_birthday%2C+publish_actions%2C+publish_stream

I don't know if this has to do anything with the error but I did the following:

the only change that i did to the facebook.php file is rename it to Facebook.php and added this line

Facebook::$CURL_OPTS[CURLOPT_SSL_VERIFYPEER] = false;

to the __construct because I was getting this error

Invalid or no certificate authority found, using bundled information

althoug all three files facebook.php, base_facebook.php and fb_ca_chain_bundle.crt are all in the same folder, the libraries folder

at the top of the html file after the header this code:

<script type="text/javascript">
        function NotInFacebookFrame() {
            return top === self;
        }
        function ReferrerIsFacebookApp() {
            if (document.referrer) {
                return document.referrer.indexOf("apps.facebook.com") != -1;
            }
            return false;
        }
        if (NotInFacebookFrame() || ReferrerIsFacebookApp()) {
            top.location.replace("<?php echo $this->config->item('fan_page_app_link'); ?>");
        }
    </script>

so that if the user is accessing the application directly from the site he will be redirected to the facebook website.

Update

If i enter the application directly from my website using this url https://MYWEBSITE.com/matchgame/register then I head back to the application from the facebook is works, it seams there is some cookie that is being blocked if i enter the application from the facebook!!!

Was it helpful?

Solution

I finally found the solution, apparently all I needed for IE to accept cross-browser cookies is a P3P policy header, all I did for since this is a PHP apps is the following bit of code prior to any page output:

header('p3p: CP="NOI ADM DEV PSAi COM NAV OUR OTR STP IND DEM"');

or this in the head block

<meta http-equiv="P3P" content='CP="NOI ADM DEV PSAi COM NAV OUR OTR STP IND DEM"' />

if you are using anything other than PHP or if you prefer meta tag over PHP code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top