$value) { // $data_check_arr[] = $key . '=' . $value; $data_check_arr[] = $key . '=' . str_replace('https:/t', 'https://t', $value); } sort($data_check_arr); $data_check_string = implode("\n", $data_check_arr); $secret_key = hash('sha256', TG_BOT_API_TOKEN, true); $hash = hash_hmac('sha256', $data_check_string, $secret_key); if (strcmp($hash, $check_hash) !== 0) { throw new Exception('Data is NOT from Telegram'); } if ((time() - $auth_data['auth_date']) > 86400) { throw new Exception('Data is outdated'); } return $auth_data; } /** * Save telegram userdata * * Save the telegram user data in a cookie * @return void */ function saveTelegramUserData($auth_data) { $auth_data_json = json_encode($auth_data); setcookie('tg_user', $auth_data_json); } function get_telegram_subscriberid($user) { global $mysqli; $stmt = $mysqli->prepare("SELECT subscriberID FROM subscribers WHERE typeID=1 AND userID LIKE ? LIMIT 1"); $stmt->bind_param("s", $user); $stmt->execute(); $result = $stmt->get_result(); if ( $result->num_rows) { $row = $result->fetch_assoc(); $subscriberID = $row['subscriberID']; return $subscriberID; } return null; // Return null on false } }