Did isset really work differently in older versions
I have legacy code that has the following:
<?PHP
if(isset($_GET['pagina'])=="homepage") {
?>
HtmlCode1
<?php
} else {
?>
HtmlCode2
<?php
}
?>
I don't know exactly why, but it seems to work. Htmlcode1 is loaded when I have it? Pagina = homepage and htmlcode2 is loaded when pagina var doesn't exist or whatever (haven't actually seen anything else, just haven't). The site uses php4 (don't know the exact version). But really, how can this work? I looked at the manual and it says isset returns bool ..
Anyone?
source to share
The problem is that "==" is not type-sensitive. Any (non-empty) string "equals" but is not identical to boolean true (you need to use the "===" operator for this).
A quick example of why you are seeing this behavior:
http://codepad.org/aNh1ahu8
And more details on this can be found in the documentation:
http://php.net/manual/en/language.operators.comparison.php
http://ca3.php.net/manual/en/types.comparisons.php ("Free comparisons with = =" on purpose)
source to share
isset()
returns true or false. In a boolean comparison, "homepage"
will evaluate to true
. Essentially, you ended up here:
if ( isset($_GET['pagina']) == true )
If pagina is equal to anything, you will see HtmlCode1. If it is not installed, you will see HtmlCode2.
I just tried it to confirm it, and going to ?pagina=somethingelse
, do not show HtmlCode2.