PHP getLoginUrl
From Facebook Developer Wiki (FbDevWiki.com)
This method returns a URL to direct the user to to have them login and grant permissions to your webpage/application.
Parameters
getLoginUrl()
takes a single argument which is an associative array of values. Here's a list of the possible values:
Name | Type | Description | Default |
---|---|---|---|
redirect_uri (v3) | string containing full URL | the url to go to after a successful login | the current URL |
scope (v3) | string containing comma separated list of extended permissions to request | comma separated list of requested extended perms | "" |
cancel_url | string containing full URL | If the person hits "cancel" on logging in or granting access to your application then the user will be directed to this URL | the current URL |
next | string containing full URL | After the person logs in and authorizes your application they will be redirected to this URL | the current URL |
display | string containing "page" or "popup" | Should the person log in through a full page and then be redirected, or should it be a smaller pop-up window? | "page" |
req_perms | string containing comma separated list of extended permissions to request | On top of the basic login and permission, these extended permissions will also be requested at the same time | "" |
Examples
Example making a simple link that will login the user:
<?php echo '<a href="' . $facebook->getLoginUrl() . '">Login</a>'; ?>
Redirecting the user depending on whether you're in an iframe or not and get extended permissions:
<script type="text/javascript"> //<![CDATA[ <?php require_once 'facebook.php'; $fb = new Facebook(array( 'appId' => $appid, 'secret' => $appsecret, 'cookie' => true )); $canvas_url = 'http://apps.facebook.com/myapp/'; $standalone_url = 'http://www.myapp.com/'; $loginperm = 'user_birthday,user_relationship_details'; $canvas_login_url = $fb->getLoginUrl(array( 'next' => $canvas_url.'game.php', 'cancel_url' => $canvas_url, 'req_perms' => $loginperm )); $standalone_login_url = $fb->getLoginUrl(array( 'next' => $standalone_url.'game.php', 'cancel_url' => $standalone_url, 'req_perms' => $loginperm )); ?> if (top.location != location) { // in canvas iframe top.location.href = "<?=$canvas_login_url?>"; } else { // stand alone site location.href = "<?=$standalone_login_url?>"; } //]]> </script>