I'm having an issue at the moment where AJAX requests are returning 500 Internal Server Errors, the code works fine on my local machine running MAMP, but as soon as I move it to another server it gives the 500 error.
I have seen that some people have had similar issues, but the majority of those cases have all resulted in typos in their code, this code works exactly as expected on MAMP.
Any advice would be greatly appreciated
Thanks
// Login AJAX
$('#login_form').on('submit', function(e) {
e.preventDefault();
var data = $(this).serialize();
$.ajax({
url: 'core/process_login.php',
type: 'post',
data: {'formdata' : data},
dataType:'json',
success: function(data) {
if(data.login_status === "failed") {
alert(data.error_msg);
}
if(data.login_status === "success") {
window.location.replace("/index.php");
}
}
});
});
<?php
require('init.php');
$formdata = $_POST['formdata'];
parse_str($formdata);
if ($ldap->authenticate($username, $password)) {
if ($ldap->user()->inGroup($username, "_BMSUsers")) {
if(userProfileExists($username)) {
createUserSession($username);
$return = array("login_status" => "success");
echo json_encode($return);
} else {
createUserProfile($username);
createUserSession($username);
$return = array("login_status" => "success");
echo json_encode($return);
}
} else {
// User is not part of the _BMSUSers AD group and therefore does not have sufficient permissions
$return = array("login_status" => "failed", "error_msg" => "You do not have permission to access the BMS System. If you think this is a mistake, please contact the IT Department.");
echo json_encode($return);
}
} else {
$return = array("login_status" => "failed", "error_msg" => "Username/Password Incorrect");
echo json_encode($return);
}
?>