my code


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 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!


// 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) {

// 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="<?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 account now.

my code 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.