我试图建立一个用户必须登录后的评论api。 伊夫隐藏评论按钮,将其设置在用户登录后显示。我怎样才能通过用户名登录
var loggeduser;
function Login(){
$.ajax({
url: 'http://creative.coventry.ac.uk/~4089797/Games/V2.0/Client4/index.php/users/account/'+$("#loginusername").val(),
headers: {Authorization:window.btoa($("#loginusername").val()+':'+$("#loginpassword").val())},
contentType: "get",
dataType: 'json',
success: function(data) {
Authorisation = window.btoa($("#loginusername").val()+':'+$("#loginpassword").val()); //create a variable to pass to the cookie
createCookie('auth',Authorisation,0); //create our authorisation cookie for the client
alert("Details correct. Please continue.");
loggeduser=username;
$("#login").hide(); //hide the login button
$("#create").hide(); //hide the create an account buttons
$("#logout").show(); //show the logout button
$("#addreview").show(); //show the add a review button
$("#adminpanel").show();//show the admin panel page
$("#loginusername").val(''); //clear the name box
$.mobile.changePage("#home"); //show the menu
},
error: function (response) {
var r = jQuery.parseJSON(response.responseText);
console.log(r);
alert("Error:" + r.error.text);
}
});
}
香港专业教育学院使用上述Ajax调用登录的用户,并试图通过此用户名去loggeduser。
function Postreview(){ //Add a review to the site
$.ajax({
type:'post',
url: 'http://creative.coventry.ac.uk/~4089797/Games/V2.0/Client4/index.php/games/review/',
data: {ean:reviewean,
review_title:$("#ReviewTitle").val(),
review:$("#Review").val(),
rating:$("#rating").val(),
username:loggeduser},
dataType: 'json',
success: function(data) {
alert("Review Added. Please continue.");
$("#reviewtitle").val(''); //clear the text boxes
$("#review").val('');
$("#rating").val('');
Getreviews(ean);
},
error: function (response) {
var r = jQuery.parseJSON(response.responseText);
console.log(r);
alert("Error:" + r.error.text);
}
});
}
这是用户帖子的审查然而,当用户提交审查的用户名字段为空,因此处理不当对
即时通讯不知道什么是一个PHP会话?并且密码将被存储为散列 – user3187726
对PHP会话进行一些研究。他们处理这种情况,所以您不必通过每个请求来验证用户身份。而base-64不是一个散列。它可以用'atob()'解码。 – bearfriend
也只是数据。 LIFE保护感谢 – user3187726