I have written a php script that I use it to upload data from a mobile (iOS) app to mysql server. The procedure works perfect and I can enter and get data from the server, but i have noticed when I post greek letters are being encoded wrongly ("Δέντρο" instead of Δέντρο). I have entered below on my php:
header('Content-Type: text/html; charset=utf-8');
but it still the data are not correct encoded. The words are not encoded correct even if I enter the data directly on the webpage instead posting them from app. The main code that I use is the following:
header('Content-Type: text/html; charset=utf-8');
require("../db/mySQL_dao.php");
$config = parse_ini_file("../../../municipapp.ini");
$returnValue = array();
if (empty($_REQUEST["name"]) || empty($_REQUEST["lon"]) || empty($_REQUEST["lan"])) {
$returnValue["status"]="400";
$returnValue["message"]="Didn't get all necessary info";
echo json_encode($returnValue);
return;
}
$issueName = htmlentities($_REQUEST["name"]);
$issue = htmlentities($_REQUEST["issue"]);
$issueComments = htmlentities($_REQUEST["comments"]);
$issueLon = htmlentities($_REQUEST["lon"]);
$issueLan = htmlentities($_REQUEST["lan"]);
$issueUserID = htmlentities($_REQUEST["userID"]);
$issueIsItOk = htmlentities($_REQUEST["isitok"]);
// Generate secure password
$salt = openssl_random_pseudo_bytes(16);
$secured_password = sha1($password . $salt);
$dbhost = trim($config["dbhost"]);
$dbuser = trim($config["dbuser"]);
$dbpassword = trim($config["dbpass"]);
$dbname = trim($config["dbname"]);
$dao = new mySQL_dao($dbhost, $dbuser, $dbpassword, $dbname);
$dao->openConnection();
// Register New Issue
$result = $dao->insertIssue($issueName, $issue, $issueComments, $issueLon, $issueLan, $issueUserID, $issueIsItOk);
if ($result) {
$issueDetails = $dao->getIssueDetails($issueName);
$returnValue["status"]="200";
$returnValue["message"]="Successfully Inserted";
$returnValue["issueId"]=$issueDetails["id"];
$returnValue["issueName"]=$issueDetails["name"];
} else {
$returnValue["status"]="400";
$returnValue["message"]="Could not insert data";
}
$dao->closeConnection();
echo json_encode($returnValue);