Forum Moderators: coopster

Message Too Old, No Replies

Register Globals!

a few questions about the built in arrays....

         

dreamcatcher

10:49 pm on Apr 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok, I`m new to PHP and I`m writing a script that assumes register globals are off, I think this is the best way to go for a beginner.

Lets take the $HTTP_POST_VARS built in array. I`m confused at how and when I need to use it.

If I have a basic contact form:


<form method="post" action="<? PHP_SELF;?>">
Name: <input type="text" name="name">
E-Mail: <input type="text" name="email">
Message: <textarea name="comments" rows="6" cols="45"></textarea>
<input type="submit" name="submitform"
value="Submit" title="Submit"></form>

So, I do some syntax as follows:

if ($HTTP_POST_VARS['submitform'])

{

do actions

}

Is that the only time I need to use the built in array? If I call to the variables $name, $email, or $comments do I need to use $HTTP_POST_VARS['name'] etc etc?

And what about functions? If I`m using $name, $email or $comments inside another function, should I declare $HTTP_POST_VARS as a global variable in the function? As you can see I`m a little confused. I`ve been looking at some other scripts for some guidelines, but would be interested to hear your thoughts.

Any help you can give me would be appreciated. Or if there are any online tutorials you can point me to, that would be just as good.

Thank you! :)

mavherick

3:37 am on Apr 9, 2003 (gmt 0)

10+ Year Member



Your assumption about using $HTTP_POST_VARS is right, but it's depecrated and you should now use $_POST wich works the same way ($_POST['submit'] for example).

You can use $_POST[] pretty much anywhere in your script, aside from classes I think (someone knows for sure?).

What I like to do is simply intialize the vars I need at the beginning of the script like for example:

if(isset($_POST['submit'])) { $submit = $_POST['submit']; }

and then I pass those to my function as parameters but that's just me.

If you need more info, the manual [php.net] is your friend.

mavherick

dreamcatcher

7:02 pm on Apr 9, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks for the information mavherick. I was worried about maybe over using $_POST, but sounds like everything will be fine.

:)