README.md

December 5, 2022 ยท View on GitHub

^ A time Saver Script

Description

In the latest version of PHP, you must use GET and POST arrays to pass variables--That's not bad--you just write foo=foo=_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
ByDarryl Porter
LevelBeginner
User Rating3.4 (82 globes from 24 users)
CompatibilityPHP 4.0
CategoryControls/ Forms/ Dialogs/ Menus
WorldPHP
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>
<input="text" name="foo" value="">
<input="submit">
</form>

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"; 
$handle = fopen ($file, "a+");
/*Replace $_POST with $_GET here as well if you need to.*/
fwrite ($handle, "<?php $$key = \$_POST[\"$key\"]; ?>"); 
fclose ($handle);
}
/* 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)) { 
unlink("$file");
}
And that is that. If you like it, please vote for it, or else just leave a comment.
-----------------------------------