im posting data with ajax to PHP, this code is working fine in local server (im using XAMPP), but when i upload it into web server it is not taking data and showing me this error
POST http://my_server_IP/login.php 500 (Internal Server Error)
if i change dataType from json to application/json and add contentType: 'application/json; charset=utf-8',
then it is shwong another error
POST http://my_server_IP/login.php 500 (Internal Server Error)
but in local machine it is working fine, i can login with same code
here is my JQuery, AJAX code
$.ajax({
dataType: "json",
type: "POST",
data: {user: sEmail, pass: sPass},
url: "login.php",
success:function(response){
var a = response;
if(a.res=='agree'){
var st = a.role+","+a.name;
$.cookie("imgup", st, { path: '/imgup', expires: 2 });
window.location.href = "logged.php";
}else if (a.res == 'error') {
errorDisplay(a.error);
}
}
});
and this is PHP
<?php
header('Content-Type: application/json');
require_once('inc/init.php');
require_once "helper/helper.php";
$email = sanitize($_POST['user']);
$pass = sanitize($_POST['pass']);
$sql_query = $db->query("SELECT * FROM `user_admin` WHERE `username`='$email'");
if(mysqli_num_rows($sql_query) > 0){
$sql = mysqli_fetch_assoc($sql_query);
if(password_verify($pass, $sql['password'])){
$role = explode(',',$sql['role']);
if(in_array("admin", $role)){
echo json_encode(array('res' => 'agree', 'role' => 'admin','name' => $sql['id']));
}elseif(in_array("editor", $role)){
echo json_encode(array('res' => 'agree', 'role' => 'editor','name' => $sql['id']));
}elseif(in_array("user", $role)){
echo json_encode(array('res' => 'agree', 'role' => 'user','name' => $sql['id']));
}
}else{
echo json_encode(array('res' => 'error', 'error' => 'user_pass'));
}
}else{
echo json_encode(array('res' => 'error', 'error' => 'user_not_exist'));
}
?>
Error log is
PHP Fatal error: Call to undefined function password_verify() in /var/www/html/login.php on line 11, referer: http://__my_IP__/login_page.php
but that function working fine in localhost!!!
how can i fix this error?
NOTE: sanitize is the function to check html entities present in the string
php55orphp56package. - aynber