简体   繁体   English

Facebook画布URL重定向到https

[英]Facebook canvas url redirected to https

I have a Facebook app with both, canvas url and secure canvas url. 我有一个同时包含画布网址和安全画布网址的Facebook应用。

When my user opens the app within a page tab, my app reads the signed_request with the page id and delivers content for this specific FB page. 当我的用户在页面选项卡中打开应用程序时,我的应用程序将读取带有page idsigned_request并为该特定FB页面提供内容。

When my user uses https surfing in FB logs out and the next user logs in with only http surfing, my app gets redirected to the secure canvas url and my signed_request parameter is lost . 当我的用户在FB中使用https冲浪注销并且下一个用户仅使用http冲浪登录时, 我的应用程序将重定向到安全的画布url,并且我的signed_request参数丢失了 Without the signed_request parameter I can't determine which page should be served by my app. 没有signed_request参数,我无法确定我的应用程序应服务于哪个页面。

When I empty the browser cache , the right http URL of my app is used. 当我清空浏览器缓存时 ,将使用我应用程序的正确http URL。

Is there a way to always use https with FB apps, or prevent the browser from caching the https URL? 有没有办法始终将https与FB应用程序一起使用,或阻止浏览器缓存https URL?

Thanks! 谢谢!

If you want to redirect from http to https and not lose the signed_request POST parameter, you can manually snag it before the redirect and append it to the URL as a GET parameter. 如果要从http重定向到https并且不丢失signed_request POST参数,则可以在重定向之前手动将其捕获,并将其作为GET参数附加到URL。 See below! 见下文!

// Force SSL
if(443 != $_SERVER['SERVER_PORT'] || 'on' != $_SERVER['HTTPS'])
{
    $queryString = $_SERVER['QUERY_STRING'];
    $hadQueryString = '' == $queryString ? false : true;
    $baseUrl = $_SERVER['REQUEST_URI'];
    $questionMark = strpos($_SERVER['REQUEST_URI'], '?');

    if(false !== $questionMark)
    {
        $baseUrl = substr($_SERVER['REQUEST_URI'], 0, $questionMark);
    }

    if($hadQueryString && isset($_REQUEST['signed_request']))
    {
        $queryString = $_SERVER['QUERY_STRING'] . '&signed_request=' . $_REQUEST['signed_request'];
    }
    elseif(isset($_REQUEST['signed_request']))
    {
        $queryString = 'signed_request=' . $_REQUEST['signed_request'];
    }

    $newLocation = 'https://' . $_SERVER['HTTP_HOST'] . $baseUrl . '?' . $queryString;

    header('HTTP/1.1 301 Moved Permanently');
    header('Location: ' . $newLocation);
    exit();
}

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

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