*如果有兴趣,请参阅 Foursquare 对此问题的回答,作为对这篇文章的评论*
请帮忙,我还在为此奋斗:(
我创建了一个删除所有 Foursquare 相关 cookie 的按钮。使用 Firebug 检查,单击时未设置 cookie。
当用户第一次登录时,同样的程序也会删除插入到数据库中的令牌。在数据库中签入时,该行被删除。
这就是发生的事情:
- 在没有 cookie 的全新浏览器中,用户登录。
- 设置 Cookie 并在数据库中插入带有令牌和用户 ID 的行。
- 用户注销。
未设置 Cookie 并从数据库中删除行
现在,另一个用户想要登录。他/她
<a href='".$authorizeUrl."'>Log in</a>
在我的网络应用程序中单击。Foursquare 登录页面显示,但在他/她可以填写表格之前,该页面使用以前的用户令牌和信息重定向回我的 Web 应用程序!
在不发生第 6 点的情况下,我可以干净启动的唯一方法是手动从浏览器中删除所有 cookie :(
任何想法将不胜感激,我不知道该去哪里。在我正在使用的代码下方,请尝试一下,您会看到第 6 步是如何发生的。
万分感谢
<?php
ob_start();
require_once('includes/EpiCurl.php');
require_once('includes/EpiSequence.php');
require_once('includes/EpiFoursquare.php');
$logout= $_GET['logout'];
if ($logout == 'true'){ /*I'm deleting all the cookies foursquare related just in case*/
$pastdate = mktime(0,0,0,1,1,1970);
setcookie ("XSESSIONID", "", time() - 18600);
setcookie ("access_token", "", time() - 18600);
setcookie ("ext_id", "", time() - 18600);
setcookie ("LOCATION", "", time() - 18600);
setcookie("access_token", "", $pastdate);
setcookie("XSESSIONID", "", $pastdate);
setcookie("ext_id", "", $pastdate);
setcookie("LOCATION", "", $pastdate);
setcookie("_chartbeat2", "", $pastdate);
setcookie("__utmb", "", $pastdate);
setcookie("__utmc", "", $pastdate);
setcookie("__utma", "", $pastdate);
setcookie("__utmz", "", $pastdate);
$_SESSION['XSESSIONID']=false;
unset($_SESSION['XSESSIONID']);
}
$clientId = "yyyyyyyyy";
$clientSecret = "xxxxx";
$redirectUrl = 'mypage.php';
$fsObjUnAuth = new EpiFoursquare($clientId, $clientSecret);
$thecode = $_GET['code'];
if(!isset($thecode) && !isset($_COOKIE['access_token'])) { //not in yet
$authorizeUrl = $fsObjUnAuth->getAuthorizeUrl($redirectUrl);
echo"<a href='".$authorizeUrl."'>Let's log in</a>";
}else{ /*we're in*/
if(!isset($_COOKIE['access_token'])) {
$token = $fsObjUnAuth->getAccessToken($thecode, $redirectUrl);
setcookie('access_token', $token->access_token);
$_COOKIE['access_token'] = $token->access_token;
}
$fsObjUnAuth->setAccessToken($_COOKIE['access_token']);
echo "we're in";
echo"<br><a href='mypage.php?logout=true'>Logout</a>";
}
?>