Facebook app redirect

I created a facebook application that when opened with apps.facebook.com/myappperfectly points to my index.php domain and can be seen in the facebook application window, but the problem arises when I try to redirect it to my registration page, it gets redirected to my domain, I want all pages were viewed in the facebook application window. tried to use the fb: redirect sdk function, but the site says they will blame these codes.

<?php
if(preg_match('/apps.facebook.com/',$_SERVER[HTTP_REFERER])){
    $app_id = '';
    $api_key = '';
    $app_secret = '';
    $canvas_page = 'mydomain/index.php';
    $auth_url = "http://www.facebook.com/dialog/oauth?client_id=".
    $app_id."&redirect_uri=".urlencode($canvas_page)."&scope=email,user_birthday,user_interests,user_about_me";
    $signed_request = $_REQUEST["signed_request"];
    list($encoded_sig, $payload) = explode('.', $signed_request, 2);
    $data = json_decode(base64_decode(strtr($payload,'-_', '+/')), true);
    if (empty($data["user_id"])){
        echo("<script> top.location.href='".$auth_url ."'</script>");
    }else{
        $canvas_page="mydomain/register.php";
        echo ("<script> top.location.href='".$auth_url."'</script>");
    }
}else{
    echo "No facebook";
}
?>

the code works fine until echo("<script> top.location.href='" .$auth_url ."'</script>")when $canvas_page- the one that is installed in the form of the facebook application; but redirects to another page when $canvas_pagechanged to my register.php page. where am i wrong

early

+3
source share
3
<?php
    //facebook application
    //set facebook application id, secret key and api key here
    $fbconfig['appid' ] = "123456392899383";
    $fbconfig['api'   ] = "97eb2asdfasdf3f20d4421b0fe8c1b2";
    $fbconfig['secret'] = "5c1d4asdfasdf71b59806b69c386b2ca";

    //set application urls here
    $fbconfig['baseUrl']    =   "http://www.your-url.com/";
    $fbconfig['appBaseUrl'] =   "http://apps.facebook.com/appname/"; 

    $uid            =   null; //facebook user id

    try{
        include_once "facebook.php";
    }
    catch(Exception $o){
        echo '<pre>';
        print_r($o);
        echo '</pre>';
    }
    // Create our Application instance.
    $facebook = new Facebook(array(
      'appId'  => $fbconfig['appid'],
      'secret' => $fbconfig['secret'],
      'cookie' => true,
    ));

    //Facebook Authentication part
    $session = $facebook->getSession();
    $loginUrl = $facebook->getLoginUrl(
            array(
            'canvas'    => 1,
            'fbconnect' => 0,
            'req_perms' => 'email,publish_stream,status_update,user_birthday,user_location,user_work_history'
            )
    );

    $fbme = null;

    if (!$session) {
        echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
        exit;
    }
    else {
        try {
            $uid      =   $facebook->getUser();
            $me     =   $facebook->api('/me');
            //PUT THE APPLICATION CODE HERE>
        } catch (FacebookApiException $e) {
            echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
            exit;
        }
    }

    function d($d){
        echo '<pre>';
        print_r($d);
        echo '</pre>';
    }
?>

script, .

+5

$auth_url :

$canvas_page="mydomain/register.php";
echo ("<script> top.location.href='".$auth_url."'</script>");

$auth url - URL-,   $ canvas_page = 'mydomain/index.php';

0

This has nothing to do with facebook. This is ABC PHP !!!

<?php
$a = "John";
$b = "Hello " . $a;
$a = "Bob";
print $b; // returns: Hello John
$b = "\nHello " . $a;
print $b; // returns: Hello Bob
?>

Live example .

-4
source

All Articles