简体   繁体   English

在Facebook应用中的php中延迟了重定向用户

[英]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. 我已经创建了一个Facebook应用程序,我希望用户在填写表格后自动重定向,但实际上并没有真正重定向到用户Facebook主页,而是会在应用程序上显示一个Facebook链接。

<?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, 这就是我在做Facebook连接其工作方式的方式,

require '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 . 你不能用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. 在打印后进入休眠状态,然后重定向,php不会在客户端运行,它只会在休眠10分钟后发送整个输出,这不起作用并且不是您想要的,它在执行print时已经创建了标头,然后添加了另一个标头,浏览器将不遵循第二个标头。 and in fact you should get a warning by php that headers already sent. 实际上,您应该通过php收到一个警告,指出已经发送了标头。

what you need is a javascript redirect after xxx something like this: 您需要的是xxx之后的javascript重定向,如下所示:

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

尝试这个:

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, 将http://放在链接中,并确实将其重定向,

 $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. 仍然找不到延迟延迟重定向的方法,尝试了很多JavaScript,但是在Facebook中,由于iframe,我猜它无法正常工作。 only the above statement is working without any delay 仅上述声明有效地工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM