简体   繁体   English

Facebook-登录重定向后如何保留app_data中的变量?

[英]Facebook - How to keep variables from app_data after login redirect?

With much thanks to other threads here I'm able to get variables passed to a facebook app tab page (With PHP sdk ) as such if the user is already logged in to facebook: 非常感谢这里的其他线程,我能够将变量传递到Facebook应用程序选项卡页面(使用PHP sdk),例如,如果用户已经登录到facebook:

https://www.facebook.com/pages/my_dull_page/156000037732522?sk=app_305100762893495&app_data=choice%3Dmy_dull_choice https://www.facebook.com/pages/my_dull_page/156000037732522?sk=app_305100762893495&app_data=choice%3Dmy_dull_choice

//check if logged in
// if not -> login -> redirect

$data= $facebook->getSignedRequest(); $ data = $ facebook-> getSignedRequest();
$app_data = $data['app_data']; $ app_data = $ data ['app_data'];

However if the user wasn't logged in, the variables are lost after the redirect, what would be the best way to pass them over? 但是,如果用户未登录,则重定向后变量将丢失,将变量传递过来的最佳方法是什么?

Many thanks. 非常感谢。

Use the php session. 使用php会话。

session_start();

$_SESSION['variable'] = $value;

Then on the page after you redirect, you could check for the existence of the variable and set it, then destroy it. 然后,在重定向后的页面上,您可以检查变量的存在并进行设置,然后销毁它。

session_start();
if( isset( $_SESSION['variable'] ) )
{
    $var = $_SESSION['variable'];
    unset( $_SESSION['variable'] );
}

The second way, and I am not sure how you are redirecting, is to pass the variables as GET vars in the redirect.. 第二种方法(我不确定您如何重定向)是在重定向中将变量作为GET vars传递。

http://domain.com/redirect.php?var1=1&var2=2&var3=3

Then read the variables on the redirected page... 然后阅读重定向页面上的变量...

$var1 = isset( $_GET['var1'] ) ? $_GET['var1'] : NULL;

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

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