$isOk, 'result' => $result, 'error' => $error ); header("Content-type: application/json"); echo json_encode($response); exit(); } /** * Get the user IP */ public static function getClientIp() { // IP si internet partagé if (isset($_SERVER['HTTP_CLIENT_IP'])) { return $_SERVER['HTTP_CLIENT_IP']; } // IP derrière un proxy elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { return $_SERVER['HTTP_X_FORWARDED_FOR']; } // Sinon : IP normale else { return (isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''); } } /** * CHECK IF BASE64 code is an image */ public static function check_base64_image($base64) { $img = imagecreatefromstring(base64_decode($base64)); if (!$img) { return false; } imagepng($img, 'tmp.png'); $info = getimagesize('tmp.png'); unlink('tmp.png'); if ($info[0] > 0 && $info[1] > 0 && $info['mime']) { return true; } return false; } /* * Check Base64 size */ public static function getBase64ImageSize($base64Image){ //return memory size in B, KB, MB try{ $size_in_bytes = (int) (strlen(rtrim($base64Image, '=')) * 3 / 4); $size_in_kb = $size_in_bytes / 1024; return $size_in_kb; } catch(Exception $e){ return $e; } } /** * Generate random Token */ public static function generateToken(){ //Generate a random string. $token = openssl_random_pseudo_bytes(16); //Convert the binary data into hexadecimal representation. return bin2hex($token); } /** * Hash password */ public static function hash_pw($plain_pw) { // (optional) change logic here for different hash algorithm //return password_hash($plain_pw, PASSWORD_DEFAULT); return md5($plain_pw); } /** * Verify hashed password */ public static function verify_pw($plain_pw, $hashed_pw) { // (optional) change logic here for different hash algorithm //return password_verify($plain_pw, $hashed_pw); return (md5($plain_pw)==$hashed_pw); } /** * Get Real File Name */ public static function getRealFileName($fileName_) { return md5($fileName_.'_'.Constants::CONST_IMAGE_SALT); } }