PHP,GET,POST,latest,version,must,arrays,pass,
Quick Search for:  in language:    
PHP,GET,POST,latest,version,must,arrays,pass,
   Code/Articles ╗ |  Newest/Best ╗ |  Community ╗ |  Jobs ╗ |  Other ╗ |  Goto ╗ | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
PHP Stats

 Code: 80,126 lines
 Jobs: 5 postings

 
Sponsored by:

 

You are in:

 
Login



Latest Code Ticker for PHP.
Number of visitors on line
By Bossman on 11/26


Bookmark without database
By Bossman on 11/25


Click here to see a screenshot of this code!Dynamic File/Menu addon
By Jody Jacoby on 11/23

(Screen Shot)

IP Logger / Traffic Log
By Kyle Shannon on 11/23


php payday calculator
By Sam999 on 11/22


Click here to see a screenshot of this code!A ( part5 ) Powerful php code for Generating Progress Bar
By James Smith Kelleher on 11/22

(Screen Shot)

Click here to see a screenshot of this code!A ( part4 ) Powerful php code Best and Easy File Upload Program
By James Smith Kelleher on 11/22

(Screen Shot)

Click here to see a screenshot of this code!A ( part2 ) Powerful php code Authenticates User , Maintains Security and Mails Administrator
By James Smith Kelleher on 11/22

(Screen Shot)

Click here to see a screenshot of this code!A ( part1 ) Powerful php code to send HTML Format Emails
By James Smith Kelleher on 11/22

(Screen Shot)

Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!





Affiliate Sites



 
 
   

^ A time Saver Script

Print
Email
 

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
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this article(in the Beginner category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor 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....
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
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
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
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.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | PHP Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyrightę 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.