简体   繁体   English

如何验证用户的Facebook ID以防止再次重新提交

[英]how to validate the facebook ID of a user to prevent from re-submitting again

I have a picture contest using php which allows you to enter to upload or enter to vote. 我有一个使用PHP的图片比赛,允许您进入上传或输入投票。 It also only allow one facebook user to upload one picture to the event at most. 它还允许一个Facebook用户最多将一张图片上传到该事件。

How can I validate their facebook ID with MySQL data, such that the same user who already submitted once (according to the fbID) is not able to click the enter contest button again and when clicked, a msg box will pop out saying "You have already submitted once"? 如何使用MySQL数据验证他们的Facebook ID,以便已经提交过一次的同一用户(根据fbID)无法再次点击输入竞赛按钮,当点击时,会弹出一个msg框说“你有已提交一次“?

Hope you guys will give suggestions. 希望你们能给出建议。 Thanks and appreciated all of your time for helping me. 感谢并感谢您花时间帮助我。

Simply store the Facebook user ID alongside the photo submission in your database. 只需将Facebook用户ID与照片提交一起存储在您的数据库中。

I assume you'll have a table that contains the photo data; 我假设你有一个包含照片数据的表格; create a new field to store the Facebook user ID too. 创建一个新的字段来存储Facebook用户ID。 Then, when the user visits your app or whatever, check if their ID is already in the database. 然后,当用户访问您的应用程序或其他任何内容时,请检查其ID是否已存在于数据库中。 If so, don't give them the upload form but an error message; 如果是这样,请不要向他们提供上传表格,而是提供错误信息; if not, allow them to upload. 如果没有,请允许他们上传。

EDIT: Check out Facebook's SDK . 编辑:查看Facebook的SDK There should be example's on there to fetch the details of the user viewing your app's page, which includes Facebook ID. 应该有一个示例来获取查看应用程序页面的用户的详细信息,其中包括Facebook ID。 You can then use that in your script. 然后,您可以在脚本中使用它。

<?php

require 'facebook.php';

$facebook = new Facebook(array(
    'appId'  => 'YOUR_APP_ID',
    'secret' => 'YOUR_APP_SECRET',
));

$user = $facebook->getUser();

if ($user) {
    try {
        $user_profile = $facebook->api('/me');
    }
    catch (FacebookApiException $e) {
        error_log($e);
        $user = null;
    }
}

if ($user) {
    $logoutUrl = $facebook->getLogoutUrl();
}
else {
    $loginUrl = $facebook->getLoginUrl();
    echo "<script>top.location.href='$loginUrl';</script>";
    exit;
}

// if we're here, the user has successfully authenticated
// you now have access to their profile in $user_profile

$userId = intval($user_profile['id']);

// logic goes here to query database and check if $userId
// has already been used to submit a photo or not

You'll need to authenticate the user and grab the FB cookie. 您需要对用户进行身份验证并获取FB cookie。

See the documentation on the FB developer site . 请参阅FB开发人员站点上的文档。

Once you have the id, you can pull it from the db and use it to check if the user has submitted or not. 获得id后,您可以从数据库中提取它并使用它来检查用户是否已提交。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM