Search code examples
phpgettelegram-bot

telegram bot web app receives data with GET method #tgWebAppData php


This data does not exist in $_SERVER

example url wep app request

https://example.com/index.php#tgWebAppData=query_id=AAEb3dV3AgAAABvd1Xds7_Fh&user=%7B%22id%22%3A633121272%2C%22first_name%22%3A%22My%20Name%22%2C%22last_name%22%3A%22%22%2C%22username%22%3A%22My_username%22%2C%22language_code%22%3A%22uz%22%2C%22is_premium%22%3Atrue%2C%22allows_write_to_pm%22%3Atrue%7D&auth_date=1704877606&hash=7b0246bd8f3d7714057bffefb6bdd8adf2b95916e36632d352cd68e525838510

I checked $_SERVER and there was no information about it. How do I receive such $_GET data? or do I have to rework it by writing codes in the .htaccess file?


Solution

  • As others mentioned in comments, the part of a URL following a # is the "fragment" or "anchor", historically used to move the viewport within a page and without talking to the server and recently often to hold more complex clientside state. It's not sent as part of an HTTP request.

    Query strings are key=value pairs following a ? and separated by &, and are sent to the server. Given your example, that # should probably be a ?.


    You can learn about the parts of a URL, which is a kind of URI, from Wikipedia's exhaustive page on the topic or from Mozilla's web docs.

    Here's Mozilla's fancy little explanation by image: enter image description here