How to read the query string in PHP and HTML?

a URL ending with something like portal.php?key2=hello how can I get the value of “key2”?

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

$_GET['key2']

will get you the value from a query string.

$_POST['key2']

will get you the value from a form posted.

$_REQUEST['key2']

will get you either of the above if it exists.

Solution 2

var_dump( $_GET['key2'] );

Solution 3

GET data is decoded into the $_GET super-global array. See http://php.net/manual/en/language.variables.external.php

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply