| | Submitted on: 10/9/2002 3:03:22 PM
By: Darryl Porter
Level: Beginner User Rating:
By 4 Users Compatibility:PHP 4.0
Users have accessed this article 1187 times. | (About the author) |
| | In the latest version of PHP, you must use GET and POST arrays to pass variables--That's not bad--you just write $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. | |
|
Terms of Agreement:
By using this article, you agree to the following terms...
1) You may use
this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
2) You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
3) You may link to this article from another website, but ONLY if it is not wrapped in a frame.
4) You will abide by any additional copyright restrictions which the author may have placed in the article or article's description. |
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.
----------------------------------- |
| |
Other 2 submission(s) by this author
|
|
|
Report Bad Submission |
|
|
Your Vote! |
See Voting Log |
|
Other User Comments |
10/27/2002 6:52:40 AM: Wouldn't it be lots easier just to code
a loop that walks through your array an
declares the variables new? Seems a
little bit too complicated to write the
variables into a seperate file and to
include it later....
|
10/27/2002 6:19:12 PM:nkans If more than one use at one time then
it may result in conflict with the
variable values? Is it not ? Is there
anyway to get away with multiple files
to avoid clashes with the valus of post
data with the simultaneous users of the
script.
Cheers,
Kannaiyan
|
|
Add Your Feedback! |
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.
NOTICE: The author of this article has been kind enough to share it with you. If you have a criticism, please state it politely or it will be deleted.
For feedback not related to this particular article, please click here. |
|