Hi.
This is the first time ive tried to make a facebook login site.
Im trying to make a site cookie storing facebook profile information (without using facebook cookie).
Im abit confused about the flow of redirection… when i get to my register page,
it cant find the cookie im trying to create, it goes into the else (couldnt find cookie).
I was wondering if someone can point me to where im going wrong?
login.php
[php]
<?php require 'facebook-php-sdk/src/facebook.php'; $facebook = new Facebook(array( // real // /* 'appId' => '***', 'secret' => '***', */ // dev // 'appId' => '***', 'secret' => '***' , )); // See if there is a user from a cookie $user = $facebook->getUser(); // if user has session cookie, then is logged in and is redirected to homepage. if (isset($_COOKIE['mywebCookie'])) { // redirect to homepage header('HTTP/1.1 302 Found'); header('Location: http://localhost:8888/myweb.com/home.php'); exit; } // if user doesnt have session cookie, but has facebook authentication. if ($user && !isset($_COOKIE['mywebCookie'])) { try { $user_profile = $facebook->api('/me'); // create a site session cookie from facebook profile. // import config/constants /* expire in 1 hour */ setcookie("mywebCookie", $user_profile, time()+3600, "/", "http://localhost:8888/myweb.com"); // redirect to finish registration page header('HTTP/1.1 302 Found'); header('Location: http://localhost:8888/myweb.com/register.php'); exit; } catch (FacebookApiException $e) { echo ''.htmlspecialchars(print_r($e, true)).''; $user = null; } } ?>
[/php]
<!DOCTYPE html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
<body>
[php]<?php if(!$user) { ?>[/php]
<fb:login-button scope="email, user_birthday, user_location, user_subscriptions, user_website, user_education_history, user_work_history, user_events, user_interests, create_event, rsvp_event"></fb:login-button>
[php]<?php } ?>[/php]
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId: '<?php echo $facebook->getAppID() ?>',
cookie: false,
xfbml: true,
oauth: true,
status: true, // check login status
channelUrl: 'http://localhost:8888/myweb.com/channel.html' //custom channel
});
FB.Event.subscribe('auth.login', function(response) {
// window.location.reload();
window.location = " http://localhost:8888/myweb.com/register.php";
// window.location = "http://localhost:8888/myweb.com/index.php";
});
FB.Event.subscribe('auth.logout', function(response) {
window.location.reload();
// window.location = "http://myweb.com/";
// window.location = "localhost:8888/myweb.com/";
});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
</script>
</body>
</html>
register.php
[php]
<?php echo ''; require_once 'head.inc.php'; echo ''; echo '' .$_COOKIE["mywebCookie"]; }; require_once 'footer.inc.php'; echo '
[/php]