Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
04-28-2006, 03:22 AM
|
#1
|
|
Member
Registered: Aug 2004
Location: Western Australia
Distribution: Debian Lenny
Posts: 779
Rep:
|
Incorrect PHP code is working, shoud I "fix" it?
I have the following line of HTML code:
<input type='hidden' name='flag' vflag='0'></form>
I meant to type "value='0'" instead of "vflag='0'" but it works despite my basic knowledge telling me it's incorrect code.
It works because the statements included in the following are all executed by PHP:
if(isset($_POST['flag']) && ($_POST['vflag']==0)) {
some code ;
$vflag+=1;
}
Should I "fix" it?
Thank you for your help.
|
|
|
|
04-28-2006, 04:12 AM
|
#2
|
|
Member
Registered: May 2004
Location: Karlsruhe, Germany
Distribution: debian, gentoo, os x (darwin), ubuntu
Posts: 940
Rep:
|
sure it works...
<input type='hidden' name='flag' vflag='0'>
would set $_POST['flag'] with no value, so
isset($_POST['flag']) will return true.
$_POST['vflag'] is not set, therfore equals to 0
to set $_POST['vflag'] = 0 you would want
<input type='hidden' name='flag' value='0'>
<input type='hidden' name='vflag' value='0'>
on top of that, you should fix it, as it is not valid xhtml, or html.
|
|
|
|
04-28-2006, 08:49 AM
|
#3
|
|
Member
Registered: Mar 2003
Location: Berkshire, England.
Distribution: SuSE 10.0
Posts: 299
Rep:
|
Short answer: Yes. If you spot a coding bug, and you know how to fix it, you should do so. What possible reason could you have for not fixing it?
Also the PHP code seems to be confusing the field name too:
Code:
if(isset($_POST['flag']) && ($_POST['vflag']==0)) {
Is the field supposed to be called 'flag' or 'vflag'? Assuming they're both supposed to be referencing the same field, you should correct that as well as the html.
|
|
|
|
04-28-2006, 12:10 PM
|
#4
|
|
Member
Registered: Aug 2004
Location: Western Australia
Distribution: Debian Lenny
Posts: 779
Original Poster
Rep:
|
Thank you both. What i found confusing was that "vflag" not set did not return a value of 0 but a value of "".
|
|
|
|
04-28-2006, 04:13 PM
|
#5
|
|
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530
Rep: 
|
$_POST['vflag'] does not exist obviously, so an empty string ( "" ) is the value of $_POST['vflag']. If you then use it as an integer, it will be converted automatically to an integer of zero.
|
|
|
|
04-28-2006, 09:28 PM
|
#6
|
|
Member
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892
Rep:
|
To differentiate between "" and 0, use the triple-equals === for equality checks. This ensures that the types between the two operands are consistent, not merely equivalent in the course of evaluation. Example:
Code:
"" == 0 // returns true
"" === 0 // returns false
Also, whenever you find a bug, you should fix it. This practice improves not only maintainability, but also security. All security flaws are bugs, therefore less bugs means less security vulnerabilities.
|
|
|
|
04-28-2006, 10:33 PM
|
#7
|
|
Member
Registered: Aug 2004
Location: Western Australia
Distribution: Debian Lenny
Posts: 779
Original Poster
Rep:
|
Thank you all again, it's all valuable info.
|
|
|
|
| Thread Tools |
Search 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
HTML code is Off
|
|
|
All times are GMT -5. The time now is 02:56 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|