PHP Get URL parameter and its value

How do I split the url and then get its value and store the value for each input?

URL:

other.php?add_client_verify&f_name=test&l_name=testing&dob_day=03&dob_month=01&dob_year=2009&gender=0&house_no=&street_address=&city=&county=&postcode=&email=&telp=234&mobile=2342&newsletter=1&deposit=1 

PHP:

 $url = $_SERVER['QUERY_STRING']; $para = explode("&", $url); foreach($para as $key => $value){ echo '<input type="text" value="" name="">'; } 

above code will return:

 l_name=testing dob_day=3 doby_month=01 .... 

and I tried another method:

 $url = $_SERVER['QUERY_STRING']; $para = explode("&", $url); foreach($para as $key => $value){ $p = explode("&", $value); foreach($p as $key => $val) { echo '<input type="text" value="" name="">'; } } 
+6
source share
4 answers

Why not use the $ _GET global variable?

foreach ($ _ GET as $ key => $ value) {

.....

}

+5
source

php has a predefined variable, which is an associative array of the query string ... so you can use $_GET['<name>'] to return the value of the link to $_GET[] docs

You really need to look at the Code Injection page on wikipedia to make sure that any values ​​sent to the PHP script are carefully checked for malicious code, PHP provides methods to prevent this problem, htmlspecialchars

+4
source
 $queryArray = array(); parse_str($_SERVER['QUERY_STRING'],$queryArray); var_dump($queryArray); 
+4
source

You must use the $_GET array.

If the query string looks like this ?foo=bar&fuz=baz

Then you can access the following values:

 echo $_GET['foo']; // "bar" echo $_GET['fuz']; // "baz" 
+1
source

Source: https://habr.com/ru/post/904324/


All Articles