开发者

delayed redirect user in php in a facebook app

i have made a facebook app, i want the user to be redirected automatically after filling a form but it doesnt really redirect to user facebook home instead it will show a facebook link there on the app.

<?php
          print "Records added to the database";
             sleep(10);//seconds to wait..
             header("Location:http://www.facebook.com");    ?>

this is how i am doing facebook connect its workin,

requir开发者_开发问答e 'facebook.php';

$facebook = new Facebook(array(
  'appId'  => 'YOUR_APP_ID',
  'secret' => 'YOUR_APP_SECRET',
));

// Get User ID
$user = $facebook->getUser();

if ($user) {
  try {
    // Get the user profile data you have permission to view
    $user_profile = $facebook->api('/me');
    echo "<pre>";
    print_r($user_profile);
    echo "</pre>";
  } catch (FacebookApiException $e) {
    $user = null;
  }
} else {
  die('<script>top.location.href="'.$facebook->getLoginUrl().'";</script>');
}


you can't do that with php . sleep as wait after printing then redirect, php doesn't run on client side it will just send the whole output after sleeping for 10 which doesn't work and not what you want, it already created headers when you executed print, then you added another header, the browser won't obey the second header. and in fact you should get a warning by php that headers already sent.

what you need is a javascript redirect after xxx something like this:

   <script type="text/javascript"> window.setTimeout(function(){window.location="http://facebook.com";},10000) </script


try this:

echo '<fb:redirect url="'.$url.'"/>';


tried this

$loginUrl= "facebook.com";
echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";

the put http:// in the link and it did redirect it,

 $loginUrl= "http://facebook.com";
    echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";

still couldnt find a way to do a delayed redirect, tried alot of javascripts but in facebook, it wont work i guess due to iframes. only the above statement is working without any delay

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜