checkTelegramInitData

**1. Connecting the Telegram Web App script:** Insert the following code into the `<head>` section of your web page: ```html <script src="https://telegram.org/js/telegram-web-app.js"></script> ``` **2. Sending initialization data to the server:** After the page loads, send the initialization data (`Telegram.WebApp.initData`) to your server. **3. Verifying initialization data on the server:** To verify the authenticity of the initialization data, use the following function on your server: ```php function checkTelegramInitData($initData, $botToken) { parse_str(urldecode($initData), $params); $hash = $params['hash']; unset($params['hash']); ksort($params); $dataString = ''; foreach ($params as $key => $value) $dataString .= "$key=$value\n"; $dataString = rtrim($dataString, "\n"); $secret_key = hash_hmac('sha256', $botToken, "WebAppData", true); $newHash = hash_hmac('sha256', $dataString, $secret_key); return hash_equals($newHash, $hash); } ``` Official documentation https://core.telegram.org/bots/webapps#validating-data-received-via-the-mini-app