Facebook: change logout url
My web is built dynamically. I have page1.php, page2.php .. etc .but they are called by something like: index.php?page=page1
When I click the logout button it reloads page1.php instead of index.php?page=page1
How do I have to change the code for the correct reload to happen, what do I have to edit?
Here's the code I'm using:
I have the logout button in this way:
<a href="<?php echo $logoutUrl; ?>"><img border=0 src="http://static.ak.fbcdn.net/rsrc.php/z2Y31/hash/cxrz4k7j.gif"></a>
Where:
$logoutUrl = $facebook->getLogoutUrl();
I'm including facebook.php and here's getLogoutUrl();:
public function getLogoutUrl($params=array()) {
return $this->getUrl(
'www',
'logout.php',
array_merge(array(
'next' => $this->getCurrentUrl(),
'access_token' => $this->getAccessToken(),
), $params)
);
}
And getCurrentUrl():
protected function getCurrentUrl() {
$protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on'
? 'https://'
: 'http://';
$currentUrl = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$parts = parse_url($currentUrl);
// drop known fb p开发者_开发百科arams
$query = '';
if (!empty($parts['query'])) {
$params = array();
parse_str($parts['query'], $params);
foreach(self::$DROP_QUERY_PARAMS as $key) {
unset($params[$key]);
}
if (!empty($params)) {
$query = '?' . http_build_query($params, null, '&');
}
}
// use port if non default
$port =
isset($parts['port']) &&
(($protocol === 'http://' && $parts['port'] !== 80) ||
($protocol === 'https://' && $parts['port'] !== 443))
? ':' . $parts['port'] : '';
// rebuild
return $protocol . $parts['host'] . $port . $parts['path'] . $query;
}
Thanks a lot!
When calling
$logoutUrl = $facebook->getLogoutUrl();
you can tell him where do you want him to return the user once he loges out:
$logoutUrl = $facebook->getLogoutUrl( array( 'next' => 'http://mydomain.com/index.php?page=page1' ) );
精彩评论