confused about cookies and redirecting

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 '
'; require_once 'header.inc.php'; if (isset($_COOKIE['mywebCookie'])) { require_once 'register.content.php'; } else{ echo ' // you are not logged in' .'
' .$_COOKIE["mywebCookie"]; }; require_once 'footer.inc.php'; echo '
'; ?>

[/php]

I haven’t done much facebook integration stuff myself, but I’m curious if there is an issue with your “channel” being set to ‘http://localhost…’.

Does facebook not postback to this address (and won’t be able to resolve localhost). - Should this not be a public facing web address?

i tried commenting out the channel file ( apparently not always required). no luck.
the cookie is not being created, but i dont understand why.

PHP Notice:  Undefined index: mywebCookie in /Applications/MAMP/htdocs/myweb.com/register.php on line 19

is it something to do with when the javascript kicks in?
because i have both the javascript (when facebook authenticates) and php (headers) redirecting to register.php but im not sure if that is correct (cos im a n00b at php/facebook/javascript).
I have however tried commenting out the php header redirect and it didnt change, still cant find cookie.
:o
I think if a ninja doesnt arrive over night, i will try a live version see if anything differs.

Sponsor our Newsletter | Privacy Policy | Terms of Service