<form action="<?=$PHP_SELF;?>" method="get"> does not work

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
jdmfontz
Forum Newbie
Posts: 17
Joined: Wed Apr 15, 2009 12:38 pm

<form action="<?=$PHP_SELF;?>" method="get"> does not work

Post by jdmfontz »

Wondering why "<?=$PHP_SELF;?>" does not seem to be working for me on this particular server. On other installations it works fine. Is there a PHP configuration parameter I don't know about that need to set?

<h1> Search v2.1</h1>
<p>
<form action="<?=$PHP_SELF;?>" method="get">
<p>
Select Protocol/Apps: <select name="apps">
<option value=" ">Choose</option>
<option value="http">HTTP</option>
<option value="dns">DNS</option>

...

Thank you in advance.
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: <form action="<?=$PHP_SELF;?>" method="get"> does not work

Post by papa »

TRy

Code: Select all

<?php echo $_SERVER['PHP_SELF']; ?>
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: <form action="<?=$PHP_SELF;?>" method="get"> does not work

Post by requinix »

Actually, use SCRIPT_NAME. Using PHP_SELF opens yourself up to various attacks.

Code: Select all

<?php echo $_SERVER['SCRIPT_NAME']; ?>
$PHP_SELF was created automatically because of register_globals. Which is a bad thing so don't use it.
jdmfontz
Forum Newbie
Posts: 17
Joined: Wed Apr 15, 2009 12:38 pm

Re: <form action="<?=$PHP_SELF;?>" method="get"> does not work

Post by jdmfontz »

Hmm, this works good. Wondering why my other syntax (<form action="<?=$PHP_SELF;?>" method="get">
) worked in one case but not in another...

Even tried <form action="<?php =$PHP_SELF;?>" method="get">
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: <form action="<?=$PHP_SELF;?>" method="get"> does not wo

Post by McInfo »

Question:
jdmfontz wrote:Wondering why my other syntax (<form action="<?=$PHP_SELF;?>" method="get">
) worked in one case but not in another...
Answer:
tasairis wrote:$PHP_SELF was created automatically because of register_globals. Which is a bad thing so don't use it.
Clarification:
When $PHP_SELF is set, register_globals (in php.ini) is on. When only $_SERVER['PHP_SELF'] is set, register_globals is off.

Edit: This post was recovered from search engine cache.
Last edited by McInfo on Mon Jun 14, 2010 4:09 pm, edited 1 time in total.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: <form action="<?=$PHP_SELF;?>" method="get"> does not work

Post by requinix »

jdmfontz wrote:Even tried <form action="<?php =$PHP_SELF;?>" method="get">
The =$var method (echo's "short(cut) syntax") only works with short tags. So

Code: Select all

<?php =$PHP_SELF; ?>
will actually throw an error.
Post Reply