【发布时间】:2018-04-05 15:30:42
【问题描述】:
我正在制作一个允许用户通过 google 登录的网站,我需要能够将姓名、电子邮件和用户图像 URL 发送到服务器。我目前正在使用 AJAX 来执行此操作。以下是我使用的功能:
function onSignIn(googleUser){
var profile = googleUser.getBasicProfile();
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if(this.readyState == 4 && this.status == 200){
document.getElementById('php').innerHTML = this.responseText;
}
};
xhttp.open('POST', "google_sign_in.php", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send('name=' + profile.getName() + '&image=' + profile.getImageUrl() + '&email=' + profile.getEmail());
}
这会将所有信息发送到服务器。没有什么可以阻止用户使用诸如 Firebug 之类的网络检查工具将 xhttp.send 函数中的值更改为:
xhttp.send(name=fakename&imagefakeimg.jpg&email=fake@information.com);
我做了一些阅读并得出结论,我不应该依赖客户端安全性(试图阻止 Web 检查器),应该进行更多的服务器端验证。
我可以访问 HTML、CSS、JS 和 PHP。如何防止用户输入无效信息?
注意:如果需要的话,我愿意学习其他将客户端信息发送到服务器的方法。另外,我无法访问命令行。
【问题讨论】:
-
我认为如果您使用 google 提供的 oauth 登录 API,您可以直接从 google 服务器获取数据
标签: php ajax validation security