problems with form's variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Talex80
Forum Newbie
Posts: 5
Joined: Tue Nov 09, 2004 7:43 am
Contact:

problems with form's variables

Post by Talex80 »

hi all,

i've such code:

Code: Select all

<html>
<form>	
	Please type your name here:<br />
	<input type="text" name=userName><br /><br />
	<input type="submit" value="Submit data">
</form>
<br /><br />
You've typed: 
<?php echo $userName;  ?>

</html>
it has to work, but it's only working when i do this way

Code: Select all

<? echo $_POST&#1111;'userName']; ?>
what's the problem? maybe some settings in php.ini needed ?
could someone help me? :(
jtc970
Forum Commoner
Posts: 38
Joined: Sun Jan 18, 2004 11:49 pm

Post by jtc970 »

you could set your register_globals = On in php.ini

but the safer way would be to use the $_POST as you did
Talex80
Forum Newbie
Posts: 5
Joined: Tue Nov 09, 2004 7:43 am
Contact:

Post by Talex80 »

thx, i'll try now :)

but why it's safer if in all manuals i see code withou $_POST or $_GET ?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Talex80 wrote: but why it's safer
http://www.php.net/manual/en/security.globals.php
if in all manuals i see code withou $_POST or $_GET ?
those are bad manuals
Talex80
Forum Newbie
Posts: 5
Joined: Tue Nov 09, 2004 7:43 am
Contact:

Post by Talex80 »

to Weirdan:

thx :)
ibizconsultants
Forum Commoner
Posts: 35
Joined: Tue Sep 07, 2004 12:07 pm

Post by ibizconsultants »

Hi Talex80,

I am afraid that I dont agree with you on the bad manuals part.

Turning register_globals to ON will help you to code faster, but this poses a security risk. I could pass variables via my browser and try to get into a system.

I suggest the use of $_POST and $_GET or $HTTP_POST_VARS and $HTTP_GET_VARS.

Regards
iBizConsultants
http://www.ibizconsultants.com
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

ibizconsultants wrote:Hi Talex80,

I am afraid that I dont agree with you on the bad manuals part.
Actually you disagree with me.

register_globals is off by default since PHP 4.2.0 (released 22-Apr-2002, more than 2 years ago). Manual writers should have adopted this change and change their manuals accordingly by this time. Those who haven't write bad manuals. Aren't you convinced?
dreamfly
Forum Newbie
Posts: 3
Joined: Wed Nov 10, 2004 9:01 pm
Contact:

Post by dreamfly »

register_globals = Off => register_globals = On in php.ini file
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

of course it could just be an old manual or old web reference that was published more then 2 years ago? But yes having register_globals = on is not a good thing for all sorts of security reasons. I remeber the headache of changing piles of code to get it to work on php 4.2 and greater.
Work to standards now as it will make your life easier in the end.
Post Reply