How to capture all variables in a message (PHP)

How to capture all variables in a message (PHP)? I do not want to deal with $_POST['var1']; $_POST['var2']; $_POST['var3']; ... $_POST['var1']; $_POST['var2']; $_POST['var3']; ... $_POST['var1']; $_POST['var2']; $_POST['var3']; ... I want to repeat them all in one shot.

+7
post php forms
Jun 17 2018-10-06T00:
source share
5 answers

If you really want to print them, you can do something like:

 print_r($_POST); 

Alternatively, you can interact with them individually, doing something like:

 foreach ($_POST as $key => $value) { //do something echo $key . ' has the value of ' . $value; } 

but whatever you do. Please filter the input. SQL Injection gives everyone sleepless nights.

+26
Jun 17 2018-10-10T00:
source share

Using:

 var_dump($_POST); 
+4
Jun 17 '10 at 1:32
source share
 echo '<pre>'; print_r($_POST); echo '</pre>'; 
+3
Jun 17 2018-10-10T00:
source share

If you need POST values ​​as variables in a script, you can use the extract function, for example.

 extract ( $_GET ); 

or

 extract ( $_GET, EXTR_IF_EXISTS ); 

There are several flags you can use (check the manual); this limits the allocation to already defined variables.

You can also use the import_request_variables function.

Greetings

Jeff

+3
Feb 20 '11 at 9:11
source share

Use this function in a loop. extract ($ _GET);

-3
Nov 11 '13 at 16:00
source share



All Articles