我試圖建立一個用戶必須登錄後的評論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