PHP Facebook 会话管理
我正在使用 PHP 开发 Facebook 应用程序。 我可以使用下面的代码登录
<?php
$app_id = "XXXXXXXXXXXXXXXXX";
$canvas_page = "http://apps.facebook.com/sandysfirst/";
$auth_url = "http://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" .urlencode($canvas_page)."&scope="."publish_stream,read_stream,offline_access";
$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
if (empty($data["user_id"])) {
echo("<script> top.location.href='" . $auth_url . "'</script>");
} else {
}?>
<?php
include_once "src/facebook.php";
$app_id = 'XXXXXXXXXXXXXXXXXXX';
$application_secret = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$facebook = new Facebook(array(
'appId' => $app_id,
'fileUpload' =>true,
'secret' => $application_secret,
'cookie' => true, // enable optional cookie support
));
if ($facebook->getSession()) {
$user = $facebook->getUser();
$uid = $facebook->getUser();
$fbme = $facebook->api('/me');
echo "<br/><br/><br/><br/> Welcome ".$fbme['name'];
}
echo "<html>
,并且下面的 HTML 带有表单操作。 我想知道提交表单后如何在第二页上获得相同的用户 ID 或会话。 我没有使用 sdk 3.0 的 facebook.php 。
I am developing a facebook app using PHP.
I am able to login using the below code
<?php
$app_id = "XXXXXXXXXXXXXXXXX";
$canvas_page = "http://apps.facebook.com/sandysfirst/";
$auth_url = "http://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" .urlencode($canvas_page)."&scope="."publish_stream,read_stream,offline_access";
$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
if (empty($data["user_id"])) {
echo("<script> top.location.href='" . $auth_url . "'</script>");
} else {
}?>
<?php
include_once "src/facebook.php";
$app_id = 'XXXXXXXXXXXXXXXXXXX';
$application_secret = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$facebook = new Facebook(array(
'appId' => $app_id,
'fileUpload' =>true,
'secret' => $application_secret,
'cookie' => true, // enable optional cookie support
));
if ($facebook->getSession()) {
$user = $facebook->getUser();
$uid = $facebook->getUser();
$fbme = $facebook->api('/me');
echo "<br/><br/><br/><br/> Welcome ".$fbme['name'];
}
echo "<html>
and the HTML follows below that with a form action.
I want to know how I can get the same user id or session on the second page once the form is submitted.
I am not using facebook.php of sdk 3.0.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道 facebook api,但是从一些基本的 php 来看,您可以使用以下几种方法:
1 - 将 uid 添加为表单中的隐藏字段。
2 - 将其添加到操作 url
然而,更好的方法是使用 facebook api,几乎与您已经在那里列出的方式相同(来自
include_once "src/facebook.php";
),每次都检索 uid,否则您将面临安全黑客攻击(很容易在表单中传递虚假 uid)。I don't know the facebook api, but from some basic php there's a few methods you could use:
1 - Add the uid as a hidden field in the form.
2 - Add it to the action url
However the better way is to use the facebook api, pretty much the same way you've got it listed there already (from the
include_once "src/facebook.php";
), to retrieve the uid each time, otherwise you leave it open to security hacks (easy to pass a fake uid in a form).