my code stock.com

pascalwacker

Tutorial Part 1 - Testing
by pascalwacker

Print of Session and User Object

Snippet options

Download: Download snippet as tutorial-part-1-testing.php.
Copy snippet: For this you need a free my code stock.com account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

<?php

// Getting the session
// Abfragen der Session
$fbSession = $facebook->getSession();

// Get login or logout url depending on if a session is set
// Login oder Logout url auf grund der Session generieren
if ($fbSession) {
	echo '<a href="' . $facebook->getLogoutUrl() . '">Logout</a><br /><br />';
} else {
	echo '<a href="' . $facebook->getLoginUrl() . '">Login</a><br /><br />';
}

// Get User Object
// Abfrage des User Objekts
$fbMe = null;
if ($fbSession) {
	try {
		$uid = $facebook->getUser();
		$me = $facebook->api('/me');
	} catch (FacebookApiException $e) {
		error_log($e);
	}
}

// Now let's display some data
// So jetzt zeigen wir mal etwas an!
if ($fbMe) { ?>
	<b>Session:</b><br />
	<pre><?php print_r($session); ?></pre>
	<br /><br />
	<b>User:</b><br />
	<img src="https://graph.facebook.com/<?php echo $uid; ?>/picture"> <?php echo $me['name']; ?><br /><br />
	<b>Complete User Object:</b><br />
	<pre><?php print_r($me); ?></pre>
<?php } else { ?>
	<b>No User Connected!</b>
<?php } ?>

Create a free my code stock.com account now.

my code stok.com is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.