Getting parameters from URL by GET method

22. 08. 2019

Obsah článku

You know, you have a page open, you follow the URL and you see a question mark with some parameters. An inexperienced programmer would think that these are separate files, but lo and behold. Try to create a file that has a question mark in its name (it doesn't work). **This is the reason why this article was written**.

What is it?

Actually, the point is that it's a single file that you pass variables to via a URL, so I have, say, a index.php file, and I pass the article name to it: index.php?clanek=o-php.

Code + explanation

Superglobal variable $_GET contains keys with parameters from URL

echo $_GET['clanek'] ?? '';

Safety and length limits

The GET method is not secure, so confidential data should not be sent over it, one of the main reasons is that it is an unencrypted communication and secondly it is stored in history.

Confidential data or just everything should be sent using the POST method. GET is more suited for furmulars where it's good to show parameters (like search engines, article page) so that the page can be linked to.

The length of the GET is not unlimited! A lot of beginners pay for this. The maximum length is around 1024 characters (some places say 1088). So for longer texts, send POST with.

Jan Barášek   Více o autorovi

Autor článku pracuje jako seniorní vývojář a software architekt v Praze. Navrhuje a spravuje velké webové aplikace, které znáte a používáte. Od roku 2009 nabral bohaté zkušenosti, které tímto webem předává dál.

Rád vám pomůžu:

Související články