PHP 网站中的 Facebook 集成
我正在尝试将我现有的 php 网站与 Facebook 登录功能集成。我目前有一个简单的登录注册用户名、密码和用于激活的电子邮件,它们的详细信息存储在 MYSQL 数据库中。我想为 Facebook 用户添加额外的登录权限。我担心如何将当前的登录访问与新的 Facebook 访问集成。我的想法是,我的所有页面都要求用户登录,并且我使用 cookie 来存储会话变量,例如昵称,我用它来在页面上构建内容。
我对在网上研究过的许多方法感到困惑,有些现在已经过时了,而另一些似乎只是半解决方案。这三个不断重复出现。
A) Login.php、Register.php 和 fbReg.php 使用 fb login/register 登录创建会话并将身份验证传递给 fbReg.php 时,会出现 login.php 和 register.php,但在页面重定向后,它只是停止在那里并显示空白屏幕。
(来自 Register.php 的片段)
<script type="text/javascript">
FB.init({appId: '<?php echo $fb_app_id; ?>', status: true,
cookie: true, xfbml: true});
<?php
if ($errors == 0) {
?>
$('#form_hidden').hide();
<?php } else { ?>
checkInput('username');
checkInput('email');
checkInput('lastname');
checkInput('firstname');
checkInput('password');
checkInput('password2');
<?php } ?>
</script>
B) 旧版 Connect 身份验证 http://developers.facebook.com/docs/authentication/connect_auth/ 使用上面的链接,我构建了一些测试脚本,只是为了看看身份验证是否有效。幸运的是,在我的网站上,我有第三方广告或网络框架,但按照字母的步骤构建了一个 interstitial_page 并从我的主登录页面重定向了页面。但是我不断收到空会话。
(来自 php 登录页面的片段)
$api_key = "YOUR_API_KEY";
$interstitial_page = "YOUR_SECURE_URL"; //URL with no 3rd party apps
$url='http://www.facebook.com/login.php?api_key=' . $api_key
. '&session_version=3&next=' . urlencode($interstitial_page)
. '&v=1.0&return_session=1&fbconnect=1'
. '&cancel_url=' . urlencode($interstitial_page);
echo "Welcome to the Old Auth flow";
echo "<p>";
echo("<a href='" . $url . "'>"
. "<img src='http://static.ak.facebook.com/images/"
. "devsite/facebook_login.gif'></a>");
C) OAuth 2.0 协议 http://developers.facebook.com/docs/authentication/ 当我使用以下脚本再次使用它时:
https://www.facebook.com/dialog/oauth?
client_id=YOUR_APP_ID&redirect_uri=YOUR_URL
我尝试使用它来捕获我的新 Facebook 站点用户的用户信息并将其存储到 MySQL 数据库,然后将此经过身份验证的 facebook 访问与“正常”Web 访问用户会话集成,但失败了它具有关联的会话变量,用于用户体验。
任何帮助将不胜感激,我目前正在努力。
谢谢迈克尔,
我在 fbReg.php 上看到一个空白屏幕
I am trying to integrate my existing php site with Facebook Login functionality. I currently have a simple login registration username, password and email for activation and their details are stored in a MYSQL database. I want to add additional login access for Facebook users. I am worried about how i will be able to integrate my current login access with the new facebook access. Principal on my mind is that all my pages require users to be logged in and i use cookies to store session variables like nickname which i use to build content on my pages.
I am confused by the many approaches I have researched on the web, some are now sadly obsolete and others seem to be half solutions. These three keep re-occurring.
A) Login.php, Register.php and fbReg.php
The login.php and register.php appear when logged in using fb login/register to create a session and pass authentication to the fbReg.php but it just stops there with a blank screen after the page is redirected.
(a snippet from the Register.php)
<script type="text/javascript">
FB.init({appId: '<?php echo $fb_app_id; ?>', status: true,
cookie: true, xfbml: true});
<?php
if ($errors == 0) {
?>
$('#form_hidden').hide();
<?php } else { ?>
checkInput('username');
checkInput('email');
checkInput('lastname');
checkInput('firstname');
checkInput('password');
checkInput('password2');
<?php } ?>
</script>
B) Legacy Connect Auth
http://developers.facebook.com/docs/authentication/connect_auth/
Using the above link I constructed some test scripts just to see if the authentication would work. Fortunately on my site I have third party ads or webframes but followed the steps to the letter building a interstitial_page and redirected page from my main login page. However I keep getting a null session.
(snippet from the php login page)
$api_key = "YOUR_API_KEY";
$interstitial_page = "YOUR_SECURE_URL"; //URL with no 3rd party apps
$url='http://www.facebook.com/login.php?api_key=' . $api_key
. '&session_version=3&next=' . urlencode($interstitial_page)
. '&v=1.0&return_session=1&fbconnect=1'
. '&cancel_url=' . urlencode($interstitial_page);
echo "Welcome to the Old Auth flow";
echo "<p>";
echo("<a href='" . $url . "'>"
. "<img src='http://static.ak.facebook.com/images/"
. "devsite/facebook_login.gif'></a>");
C) OAuth 2.0 protocol
http://developers.facebook.com/docs/authentication/
when I use this again using the following script:
https://www.facebook.com/dialog/oauth?
client_id=YOUR_APP_ID&redirect_uri=YOUR_URL
I have tried and failed to use this to capture User info for my new facebook site users and store it to MySQL database then integrate this authenticated facebook access with the 'normal' web access user session since that has assocaiated session variables which are used the the user experience.
Any help would be appreciated, im struggling at the moment.
Thanks Michael
i get a blank screen on the fbReg.php
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我上周刚刚为我的网站做了这件事,所以我知道对所有方法进行排序是多么困难,其中许多方法已经过时了。这是我的方法:
我在我的网站上放置了“使用 Facebook 登录”链接,该链接会重定向到我的正常注册页面。
我的注册脚本如下所示:
在我的登录脚本中,我照常设置用户名等 cookie。
希望这有帮助!
I just did this very thing for my site last week, so I know how hard it is to sort through all of the many methods, many of which are outdated. This was my approach:
I placed the "Login in with Facebook" link on my site which redirects to my normal registration page.
My registration script looks like this:
In my login script, I set the username, etc cookies as normal.
Hope this helps!
我不知道您是否在谈论社交插件,但如果您是在谈论这些 Facebook 插件-ins 在页面中内置了生成器,它将生成您需要的代码。
如果您不是在寻找插件,而是在寻找用户信息,我仍然建议您运行生成器来获取代码,并查看 Facebook 如何获取用户信息。
遵循简单脚本的路径应该可以让您到达您需要的地方。
I can't tell if you are talking about the social plug-ins, but if you are, these Facebook Plug-ins have generators built into the pages which will generate the code you need.
If you are not looking for plugins but instead the information for the users, I still recommend that you run the generators to get the code and see how Facebook gets the information for the users.
Following the path of the simple scripts should get you to where you need to be.