if($tag == 'signin'){
// check for user
$email = mysql_real_escape_string(trim($_POST['username']));
$password = mysql_real_escape_string(trim($_POST['password']));
if(isset($email) && !empty($email) && isset($password) && !empty($password)){
$result = getUserByEmailAndPassword($email, $password);
if ($result != false) {
// user found
$response["error"] = FALSE;
$response['uid'] = $result['uid'];
$response['email'] = $result['email'];
$response['username'] = $result['username'];
$response['password'] = $result['password'];
$response['endyear'] = $result['endyear'];
$response['phone'] = $result['phone'];
$response['currentyear'] = $result['currentyear'];
$response['currentsem'] = $result['currentsem'];
echo json_encode($response);
} else {
// user not found
// echo json with error = 1
$response["error"] = TRUE;
$response["error_msg"] = "Incorrect email or password!";
header('Content-Type: application/x-www-form-urlencoded');
echo json_encode($response);
}
}else{
$response["error"] = TRUE;
$response["error_msg"] = "Required parameter 'username' or 'password' is missing!";
echo json_encode($response);
}
}
I am using the above php code for my API
am I using header('Content-Type: application/x-www-form-urlencoded'); in the right place?
Also, when I check this request on my Advanced REST client in chrome, the request is just fine. the response is below:
{"tag":"signin","error":false,"uid":"10","email":"example@exmaple.com","username":"jammy","password":"40be4e59b9a2a2b5dffb918c0e86b3d7","endyear":null,"phone":null,"currentyear":null,"currentsem":null}
However, when I run the same thing on any online response checker, the response is all garbage HTML. Same with my application hosted online
I noticed that the chrome extension by default sets the Content-Type to application/x-www-form-urlencoded
The same code used to work fine when I was running my application on xampp on localhost, however, after I uploaded this online, I am facing this issue
Could someone pls help me figure what I am doing wrong