my code


Tutorial Part 2.1 - Listen to login
by pascalwacker

Init JS + Listen to Event

Snippet options

Download: Download snippet as tutorial-part-21-listen-to-login.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!

// now we can log in with javascript! In "Part 1 - Testing" we use PHP to display the image and the name and so on. Therefore we want to relode the page on login or logout
// Jetzt können wir uns bereits mit hilfe von Javascript anmelden! In "Part 1 - Testing" benutzten wir PHP um Informationen anzuzeigen. Daher wollen wir bei login oder logout die Seite neu laden

// Place this in the body of your page
// Plaziere diesen Code im body deiner Seite ?>
<div id="fb-root"></div>

// Init the JS
// Javascript aufrufen
$session = $facebook->getSession();
<script type="text/javascript">
window.fbAsyncInit = function() {
		appId   : '<?= $facebook->getAppId(); ?>',
		<? if ($session && $session !== null): ?>session : <?= json_encode($session); ?>,<? /* don't refetch the session when PHP already has it*/ endif; ?>
		status  : true, // check login status
		cookie  : true, // enable cookies to allow the server to access the session
		xfbml   : true // parse XFBML
	// We gona listen for the login event and relode the page
	// Wir fangen den Login Event ab und laden die Seite neu
    FB.Event.subscribe('auth.login', function() {

(function() {
	var e = document.createElement('script');
	e.src = document.location.protocol + '//<?= $locale; ?>/all.js';
	e.async = true;

// now the JS should be ready! so let's try it, we also need some permissions for example creating events for the user (list of permission is here
// Jetzt sollte Javascript verfügbar sein! Probieren wir es aus, wir benötigen ebenfalls einige Berechtigungen vom User (Liste mit allen Berechtigungn kann hier gefunden werden
<br /><br /><fb:login-button perms="create_event"></fb:login-button><br /><br />

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.