37 lines
1.2 KiB
PHP
37 lines
1.2 KiB
PHP
<?php
|
|
|
|
function validateStatistics($data)
|
|
{
|
|
if (!isset($data->user_locale) || !is_string($data->user_locale) || strlen($data->user_locale) > 3) {
|
|
throw new Exception("La propriété 'user_locale' est manquante ou invalide.");
|
|
}
|
|
if (!isset($data->user_country) || !is_string($data->user_country)) {
|
|
throw new Exception("La propriété 'user_country' est manquante ou invalide.");
|
|
}
|
|
if (!isset($data->level_post_id) || !is_numeric($data->level_post_id)) {
|
|
throw new Exception("La propriété 'level_post_id' est manquante ou invalide.");
|
|
}
|
|
if (!isset($data->level_score) || !is_numeric($data->level_score)) {
|
|
throw new Exception("La propriété 'level_score' est manquante ou invalide.");
|
|
}
|
|
if (!isset($data->level_completion_time) || !is_numeric($data->level_completion_time)) {
|
|
throw new Exception("La propriété 'level_completion_time' est manquante ou invalide.");
|
|
}
|
|
}
|
|
|
|
$json = file_get_contents('php://input');
|
|
$data = json_decode($json);
|
|
|
|
|
|
write_log($data);
|
|
write_log(validateStatistics($data));
|
|
|
|
|
|
|
|
// if (isset($data->propriete) && is_string($data->propriete)) {
|
|
// write_log($data);
|
|
// write_log($cleanData = htmlspecialchars($data));
|
|
// } else {
|
|
// // Les données ne sont pas valides, gérer l'erreur
|
|
// }
|