Code: Select all
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">the URL in the address bar is http://updateacct.php/
I know I can use the file name is there any advantage to using the $_SERVER way ?
Moderator: General Moderators
Code: Select all
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">Code: Select all
<form action="<?=$PHP_SELF?>" method="post">Yes, I am categorically opposed to USING $PHP_SELF and <?=$PHP_SELF?> as this implies register_globals is on and that short_tags are also on. This will invariable cause your apps to croak in future versions of PHP that will not support register globals or short tags.timclaason wrote:What if you did:
I find the $_SERVER[] and $PHP_SELF equivalent. Not sure if anyone is categorically opposed to this, though.Code: Select all
<form action="<?=$PHP_SELF?>" method="post">
This will only work if you're on >=4.3.0.
I find it better to use the $_SERVER[] variables instead of pagenames because your page name may change or you may end up moving code to different pages.
I do run into trouble with $_SERVER variables when calling methods within a class, so if I'm doing a HTML form in the class (which is something I try to avoid), I'll use the pagename (unless I feel whacky enough to add another argument to the method, which defines the pagename). Sorry for the tangent, there.