Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-24-2003, 02:54 AM   PM User | #1
misterx
Regular Coder

 
Join Date: Dec 2002
Location: Seattle, WA
Posts: 116
Thanks: 1
Thanked 0 Times in 0 Posts
misterx is an unknown quantity at this point
form variables

I was just wondering if there is a certain way that you are definitely supposed to use variables passed to a script from a form. I usually just call the variable using the name of the form field such as $email.

But I noticed that most people seem to use either $_POST['email']

or

$HTTP_POST_VARS['email']

My question is, does it actually make a difference? Is there a good reason why I would want to use one of the longer versions rather than the way I do it? As always, thanks for the input.
misterx is offline   Reply With Quote
Old 01-24-2003, 12:10 PM   PM User | #2
Jeewhizz
Regular Coder


 
Join Date: May 2002
Location: London, England
Posts: 369
Thanks: 0
Thanked 0 Times in 0 Posts
Jeewhizz is an unknown quantity at this point
It makes it more secure. For example, assume that you had the form going to form.php. I could go to www.domain.com/form.php?email=whatever and it'd process it.....

Jee
__________________
Jeewhizz - MySQL Moderator
http://www.sitehq.co.uk
PHP and MySQL Hosting
Jeewhizz is offline   Reply With Quote
Old 01-24-2003, 12:26 PM   PM User | #3
mordred
Senior Coder


 
Join Date: Jun 2002
Location: frankfurt, german banana republic
Posts: 1,848
Thanks: 0
Thanked 0 Times in 0 Posts
mordred is an unknown quantity at this point
It also improves readability of your good immensely. Think of a script, 500 lines long, that you haven't touched a year long. Then you suddenly need to make some changes to it, and you run into a bunch of undeclared variables that seem to come from anywhere. No indication (if you don't explicitly comment this) is left *where* the variables come from - GET, POST, cookies, session, server environment... no one knows for sure unless you take the burden of testing this script in a context it's normally used.
Compared against $_POST, it's immediately clear where the variable is supposed to come from. Plus, the new $_POST|GET|etc. predefined variables are super-globals, which means you can access them in functions without the need to import them with the "global" keyword.
mordred is offline   Reply With Quote
Old 01-24-2003, 06:42 PM   PM User | #4
misterx
Regular Coder

 
Join Date: Dec 2002
Location: Seattle, WA
Posts: 116
Thanks: 1
Thanked 0 Times in 0 Posts
misterx is an unknown quantity at this point
Awesome. Thanks for the info. I knew there had to be a reason I just couldn't think of what it was.
misterx is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:54 AM.


Advertisement
Log in to turn off these ads.