我想寫一個自定義的授權/取消授權腳本使用Facebook的OAuth憑證我的網站。我可以張貼令牌到我的數據庫,但是當我刪除令牌和刷新頁面,它只是再次張貼的標誌,即使我沒有點擊授權鏈接。Facebook的訪問令牌/登錄
我authorize.php:
<div class="authorize_btn" style="float:right; margin-top:-35px; padding-right:10px">
<?php
$db_conx = mysqli_connect("localhost","root","","test");
if (mysqli_connect_errno())
{
echo mysqli_connect_error();
exit();
}
$sql = "SELECT fb_token FROM users";
$user = $_SESSION['username'];
$query = mysqli_query($db_conx, $sql);
$row = mysqli_fetch_array($query);
$login = $facebook->getLoginUrl();
$access_token = $facebook->getAccessToken();
$fb_token = $row[0];
if (empty($fb_token))
{
$add_user = "<a href='$login'>Add User</a>";
echo $add_user;
if ($add_user)
{
$sql = mysqli_query($db_conx, "UPDATE users SET fb_token='$access_token' where username='$user'");
}
}
else
{
echo "<form id='deauth' action='deauth_fb.php' method='post'>";
echo "<a href='#' onclick='document.forms[0].submit();'>Deauthorize User</a>";
echo "</form>";
}
?>
</div>
我deauth_fb.php:
<?php
session_start();
include ('inc/facebook.php');
include ('fbconfig.php');
$db_conx = mysqli_connect("localhost","root","","test");
if (mysqli_connect_errno())
{
echo mysqli_connect_errno();
exit();
}
$facebook = new Facebook(array(
'appId' => APP_ID,
'appSecret' => APP_SECRET,
));
$user_session = $_SESSION['username'];
$delete_sql = mysqli_query($db_conx, "UPDATE users SET fb_token='' where username='$user_session'");
header('location:home.php');
?>