Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 保存facebook签名请求?_Php_Facebook - Fatal编程技术网

Php 保存facebook签名请求?

Php 保存facebook签名请求?,php,facebook,Php,Facebook,形势 我正在玩新的Facebook iFrame标签页。我正在使用已签名的请求获取有关应用程序、页面和用户的一些事实 挑战 Facebook仅在iframe的第一次调用中通过$请求提供签名的\u请求参数。问题是第二次访问parms,例如,对于ajax请求 我就是这样做的 我像这样扩展了PHPSDK,将签名的请求存储在cookie中 /** * The name of the Cookie that contains the session. * @return String the cook

形势
我正在玩新的Facebook iFrame标签页。我正在使用已签名的请求获取有关应用程序、页面和用户的一些事实

挑战
Facebook仅在iframe的第一次调用中通过$请求提供签名的\u请求参数。问题是第二次访问parms,例如,对于ajax请求

我就是这样做的
我像这样扩展了PHPSDK,将签名的请求存储在cookie中

/**
 * The name of the Cookie that contains the session.
 * @return String the cookie name
 */
protected function getSessionSignedRequestCookieName() {
    return 'fbs_sr_' . $this->getAppId();
}

/**
 * Saves the signed_request as a browser coookie
 * @return void;
 */
protected function saveSignedRequestAsCookie($signedRequest) {
    $cookieName = $this->getSessionSignedRequestCookieName();

    setcookie($cookieName, serialize($signedRequest));
}

/**
 * Returns the SigndRequest from $_COOKIE
 * @return array
 */
public function getSignedRequestFromCookie() {
    $cookieName = $this->getSessionSignedRequestCookieName();

    if(isset($_COOKIE[$cookieName])) {
        $this->signedRequest = $_COOKIE[$cookieName];
        return unserialize($this->signedRequest);
    } else {
        return NULL;
    }
}

/**
 * Returns the data from a signed_request token provided by $_REQUEST or $_SESSION
 * @return array The decoede signed Request
 */
public function getSignedRequest() {
    $signedRequest = parent::getSignedRequest();

    if($signedRequest != NULL) {
        $this->saveSignedRequestAsCookie($signedRequest);
        return $signedRequest;
    } else {
        return $this->getSignedRequestFromCookie();
    }
}
你怎么想*
我认为这是个好主意还是个坏办法?有什么建议/改进吗?

建议的解决方案对我有效,但有一个小缺陷:unserialize返回一个空对象,因此我保存了签名请求的base64编码json格式(Facebook发送到canvas应用程序的格式)

嗨,我喜欢你的代码。我用它来得到签名的请求。但我得到了这个错误:致命错误:无法访问父::当当前类作用域没有父时,为什么?谢谢Dibsy你需要扩展官方的facebook php sdk。你认为会话会以同样的方式工作吗?为什么不使用它们,为什么使用cookies?