duana1021 2013-01-15 09:31
浏览 66

Facebook javascript + php,如何保证数据的有效性?

Im using the javascript SDK of facebook in the frontend:

jQuery("#pct_fbbutton").live("click",function(){
        FB.getLoginStatus(function(response) {
        if (response.status === 'connected') {
            console.log('Conected');
            FB.api('/me/likes', function(response) { user_likes = response;
            FB.api('/me', function(response)       { user       = response; 
                send_server(user, user_likes);
            });
            });

        } else if (response.status === 'not_authorized') {
            console.log('not_authorized');
            login();
        } else {
            console.log('not_logged_in');
            login();
        }
    });
});

As you can see, after the user is login with facebook ill send two objects via AJAX to a php script (using the function send_server).

I can access in the backend the currently generated token with $facebook->getAccessToken(), but as I know this is retrived from a cookie made by the javasript sdk, considering that all frontend data can be hacked, using the token how can ensure that the user data is valid on php?

  • 写回答

2条回答 默认 最新

  • dsmvqp3124 2013-01-15 09:36
    关注

    The answer is to perform the graph calls with PHP instead of JavaScript, especially if the only purpose of your client-side script is to send it to the server;

    Doing the data gathering on the server is the only practical way you can be sure that the data has not been tampered with, assuming you do proper https certificate checking.

    The validity of the access token is also easy, because Facebook will return an error if the provided access_token value is invalid.

    评论

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据