Page 1 of 1

facebook SDK [SOLVED] take a peek if you have trouble!

Posted: Tue Feb 07, 2012 10:58 pm
by Torniquet
This thing is really starting to grate my goat now!

I click the 'logout' button, yet i remain logged into my site via facebook...

I am using the php SDK, code to follow.

Can somone tell me how to work this bloody thing! :)

index

Code: Select all

<?php
require_once("core/init.php");
require_once("core/function.php");

/*if($session) {
	header("Location: signup.php");
	exit;
}*/

?>
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Home page</title>
<link href='http://fonts.googleapis.com/css?family=Macondo' rel='stylesheet' type='text/css'>
<link href='/style/main.css' rel='stylesheet' type='text/css'>
</head>

<body>
<?=$logUrl?>
<div id="wrapper">
	<h1>Blood Hunt</h1>
    <div>
    	<a href="<?=$loginUrl?>" id="fb-login"></a>
    </div>
    <div>
    	<p>Blood Hunt is in pre Alpha.</p>
        <p>Use your Facebook account to login. All information accessed by Blood Hunt is kept private and is not stored in our system.</p>
    </div>
</div>
</body>
</html>
facebook crap

Code: Select all

require_once($_SERVER['DOCUMENT_ROOT'] . "/libs/facebook.php");
$facebook_config = array(
	"appId"		=>	"*********************",
	"secret"	=>	"*********************"
);

$facebook = new Facebook($facebook_config);

$session = $facebook->getUser();
$me = null;

if($session)
{
	try
	{
		$me = (object)$facebook->api('/me');
	}
	catch (FacebookApiException $e)
	{
		echo $e;
		$me = null;
	}
}

if($me)
{
	$login_options = array("next" 	=> "http://www.blood-hunt.tapt-in.net/logout.php");
	$logoutUrl = $facebook->getLogoutUrl($login_options);
	$logUrl = "<a href='$logoutUrl'>Log out</a>";
}
else
{
	$login_options = array(
		"redirect_uri" 	=> "http://www.blood-hunt.tapt-in.net",
		"scope"			=>	"email,read_stream,publish_stream,user_photos,read_mailbox,offline_access"
	);
	$loginUrl = $facebook->getLoginUrl($login_options);
	$logUrl = "<a href='$loginUrl'>Log in</a>";
}
logout

Code: Select all

<?php
require_once("core/init.php");
unset($_SESSION);
unset($_COOKIE);
?>
ta xxx

Re: facebook SDK

Posted: Wed Feb 08, 2012 7:45 am
by Chris
I'm guessing it sends an encryption key and a password to Facebook, then lets you make access to the API server. Couldn't be that difficult to figure out. What is in $me? print_r($me).

Re: facebook SDK

Posted: Wed Feb 08, 2012 9:02 am
by Torniquet
$me contains all of my facebook information returned by the API. Username, name, email, etc etc

You woulda thought it wouldnt be that hard to use it, but it is a sodding pain in the ass!

Re: facebook SDK

Posted: Wed Feb 08, 2012 6:41 pm
by Torniquet
I appear to fixed the effin thing :D

new logout.php

Code: Select all

<?php
require_once("core/init.php");
unset($_SESSION);
setcookie("PHPSESSID", "", time() - 1000);
header("Location: index.php");
?>