README.md
December 5, 2022 ยท View on GitHub
Description
In the latest version of PHP, you must use GET and POST arrays to pass variables--That's not bad--you just write _GET["foo']; and you use $foo--But say you have 80 variable to declare--then it gets time consuming. This will cut the time to nothing.
More Info
| Submitted On | |
| By | Darryl Porter |
| Level | Beginner |
| User Rating | 3.4 (82 globes from 24 users) |
| Compatibility | PHP 4.0 |
| Category | Controls/ Forms/ Dialogs/ Menus |
| World | PHP |
| Archive File |
Source Code
With the advent of newer version of PHP you can't do
some
of the convenient stuff that you used to be able to do. One of
which is, you can no longer
pass variable from one page to the other with a form without using the
super-global variables $_POST
or $_GET. These were introduced for
security reasons, but it
make
coding that much longer because before you can use a variable you
must
declare it using the super-global so your code end up looking like this:<form method=POST>You pass this form to the next page and your code looks like this: $foo = $_POST["foo"]; Now you can use $foo like in older version of PHP. You might say, what's wrong with that. I say nothing--unless you have over 80 variable to declare, then it becomes tedious. However, with this little script, it does the work for you. ------------------------------------------------------------------ /*I use a WHILE LOOP to run throught the GET or POST array. You could also use a FOREACH LOOP. If you are using $_GET, just replace $_POST with $_GET */ while(list($key,$value)= each($_POST)) /* Creates a file called variable */ $file = "variables.php";/*Replace $_POST with $_GET here as well if you need to.*/ fwrite ($handle, "<?php $$key = \$_POST[\"$key\"]; ?>");/* Includes the file filled with your varaibles. You can now use the variable like you used to under the previous versions of PHP. */ include ("variables.php");
/* Put this at the bottom of your page. It destroys
the file "variables.php"
*/ if (file_exists($file)) { And that is that. If you like it, please vote for it, or else
just leave a comment.----------------------------------- |