klemme 3 Posting Whiz in Training

Hi all,

I have created a small test app - And I want to login users when they first arrive to the app - and log them out and redirect them after they have used it. Quite simple right, but using facebook php sdk - I am not able to do such a thing.

I can only login to the app, if i am logged in to my own private facebook account - so the getLoginUrl(); doesnt redirect if the user is not logged into his/her facebook account.

And the log out, and setting sessions to null, session_destroy(); etc, doesnt work at all, it seems i cant get rid of the facebook session, even after i have logged out of my own facebook page, i am still able to type the app url in the adress bar, and go straight to the app without authentication, and this is after i have logged out (or tried to..)

When i am logged in to the app, and clicking the logout link, it looks like i get logged out, cause all the adds go away, but my redirects dont work, and the actual app is still "open"/logged in to.

This is my index page where the users gets access:

<?php
ob_start();
header('Content-Type: text/html; charset=utf-8');
echo '<link rel="stylesheet" type="text/css" href="app_style.css"/>';
require("facebook.php");
?>
<!-- Facebook anbefal/send script JS SDK-->
<div id="fb-root"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/da_DK/all.js#xfbml=1&appId=343530502333265";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<!-- Facebook script slut -->
<?php
// Create application instance:
$facebook = new Facebook(array(
'appId' => '343530502333265',
'secret' => 'xxx',
'cookie' => 'true',
));

// Create logout url, and set the redirect page after clicked: (*****DOESNT WORK*****)
// SHOULD THIS BE THE WEBSITES ADRESS?
$params = array( 'next' => 'http://apps.facebook.com/enkelt-webdesign/logout.php' );

$LogOutUrl = $facebook->getLogoutUrl($params); // $params is optional. 

$session = $facebook->getUser();
if (!empty($session))
{
		try {
			$uid = $facebook->getUser();
			$user = $facebook->api('/me'); // logged in user
		} catch (Exception $e) {}
	
	if(!empty($user)) // show content
	{
		
		if ($_GET['installed'] == '1')
		{
			header("location: http://apps.facebook.com/enkelt-webdesign");
		}
		
		// Content start:
		echo '<div id="container_left">';
		echo '<a class="left_link" href="http://www.enkelt-webdesign.dk" target="_blank">Læs mere på: enkelt-webdesign.dk</a>';		
		echo '</div>';
		
		echo '<div id="container_right">';

		echo '<div id="header">';
		echo 
		'<ul>
				
		<div style="width:325px; height:25px; border:1px solid #CCC; 
		padding-left:10px; padding-top:5px;"><!-- FB Like/Send div -->
      		<fb:like href="http://apps.facebook.com/enkelt-webdesign/" send="false"
 layout="button_count"
                    width="90" show_faces="true" action="recommend" colorscheme="dark" font="tahoma"">
                    </fb:like><p style="display:inline; margin-left:-35px;">Enkelt-webdesign på Facebook!</p>
               </div>	
			</ul>';
			echo '</div>';
// IN THE NAV JUST BELOW, I HAVE THE LOGOUT ($LogOutUrl) IN THE LAST LINK, NOTHING HAPPENS WHEN 
// IT IS CICKED	
	echo '<div id="content">';
		echo '<div id="navigation">';
			echo '<ul><a href="index.php?side=hjem">Hjem</a>';
				echo '<a href="index.php?side=wall">Væg</a>';
				echo '<a href="index.php?side=cases">Cases</a>';
				echo '<a href="index.php?side=boost">Website boost</a>';
				echo '<a href="index.php?side=more">Lær mere</a>';
				echo '<a href="'.$LogOutUrl.'">Log Ud</a>'; // NOT WORKING
				echo '</ul>';
				echo '</div>';
					
				echo '<div id="profil-img-div">';
				echo '<img src="https://graph.facebook.com/'.$uid.'/picture?type=normal" 
				width="100px;" height="100px;" style="border:2px solid #333;"/>';
				echo '</div>';
				echo '<div style="clear:both;"></div>';
				echo '<div id="name_div">
				<p style="display:inline;">Hej '.$user['first_name'] .' '.$user['last_name'].'!</p>
				</div>';
				echo '<div id="core_content">';	
        					
			if (isset($_GET['side']) && $_GET['side'] == 'wall')
			{
				include("includes/wall.php");
			} 
			elseif (isset($_GET['side']) && $_GET['side'] == 'cases')
			{
				include("includes/cases.php");
			}
			elseif (isset($_GET['side']) && $_GET['side'] == 'boost')
			{
				include("includes/boost.php");	
			}
			elseif (isset($_GET['side']) && $_GET['side'] == 'more')
			{
				include("includes/more.php");
			}
			else
			{
				include("includes/home.php");	
			}

			echo '</div>';// Core content slut
			echo '</div>';// Content slut
		
		echo '</div>';
	}
	else die('Hov der er vist sket en fejl, prøv at genopfriske siden eller log ind igen!');
}	
else  // if user is not logged in or have allowed the app, i want to redirect to a page called logout.php - not the best name - but logout.php should tjeck and log a user out, kill the session made by facebook, and display a link to log in:
{
	header("location: logout.php");
	exit();
}
?>

Here is logout.php: I have tried so many things, and this is the last not working example..:

<?php
ob_start();
header('Content-Type: text/html; charset=utf-8');
echo '<link rel="stylesheet" type="text/css" href="app_style.css"/>';
require("facebook.php");
?>
<!-- Facebook anbefal/send script JS SDK-->
<div id="fb-root"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/da_DK/all.js#xfbml=1&appId=343530502333265";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<!-- Facebook script slut -->

<?php
// Create application instance:
$facebook = new Facebook(array(
'appId' => '343530502333265',
'secret' => '075621a8a92fa36ebfafc8057b12f4e6',
'cookie' => 'true',
));

// DO I NEED TO SET COOKIE TO TRUE HERE?
// I found this on the net, and cant get it to work:
setcookie('fbs_'.$facebook->getAppId(), '', time()-100, '/', 'enkelt-webdesign.dk/facebook');
// Might be wrong url, should it be apps url?
session_destroy();
//header('Location: http://apps.facbook.com/enkelt-webdesign/logout.php');

// THE LOGIN URL IS IN A LINK FURTHER DOWN; AND NOTHING AT ALL HAPPENS WHEN CLICKED:?
$params = array(
  'scope' => 'read_stream, friends_likes',
  'redirect_uri' => 'http://apps.facebook.com/enkelt-webdesign/'
);

$LogInUrl = $facebook->getLoginUrl($params);

?>
	
<div id="container_left">
<a class="left_link" href="http://www.enkelt-webdesign.dk" target="_blank">Læs mere på: enkelt-webdesign.dk</a>		
</div>
		
<div id="container_right">

<div id="header">
			 
<ul>
				
<div style="width:325px; height:25px; border:1px solid #CCC; 
padding-left:10px; padding-top:5px;"><!-- FB Like/Send div -->
<fb:like href="http://apps.facebook.com/enkelt-webdesign/" send="false" layout="button_count" 
 width="90" show_faces="true" action="recommend" colorscheme="dark" font="tahoma"">
</fb:like><p style="display:inline; margin-left:-35px;">Enkelt-webdesign på Facebook!</p>
</div>	
</ul>
</div>
	
<div id="content">
<div id="navigation">
<ul>
<a href="#">Hjem</a>
<a href="#">Væg</a>
<a href="#">Cases</a>
<a href="#">Website boost</a>
<a href="#">Lær mere</a>
</ul>
</div>
<div style="clear:both;"></div>
<div id="name_div">
					
</div>
<div id="core_content">

<div style="margin-left:50px; margin-top:150px;">

// THIS LINK IS NOT WORKING EITHER:
<h2 style="display:inline;"><a class="log_in_link" href="<?php echo $facebook->getLoginUrl($params); ?>">Klik her</a> for at logge ind/tilføje enkelt-webdesign til dine applikationer!</h2>
</div>
					
</div>
</div>
		
</div>

It is somewhat basic functionality, that I cant get to work using facebooks php SDK

Is it done simple in javescript?

Or am I close to getting it right?

Regards, Klemme