cgimusic Posted December 3, 2009 Share Posted December 3, 2009 I have a really weird problem with some code I wrote: <?php echo file_exists("includes/".$_GET["page"].".inc.php"); if($_GET["page"]=""||!isset($_GET["page"])){ include "includes/main.inc.php"; } elseif(file_exists("includes/".$_GET["page"].".inc.php")){ include "includes/".$_GET["page"].".inc.php"; }; ?> The elseif part does not execute despite the fact that echo file_exists("includes/".$_GET["page"].".inc.php"); returns "1" w/o quotes and the file definitely does exist. I believe it is the $_GET part that is causing the problem because when I do elseif(!file_exists("includes/".$_GET["page"].".inc.php")){ I get the error "Warning: include(includes/.inc.php) [function.include]: failed to open stream: No such file or directory" It is probably just a really stupid mistake but I can't figure out is wrong. I would much appreciate any enlightenment you may have to offer. Link to comment https://forums.phpfreaks.com/topic/183904-file_exists-wont-activate-if-statement/ Share on other sites More sharing options...
mrMarcus Posted December 3, 2009 Share Posted December 3, 2009 it appears that $_GET['page'] is empty/does not contain a value. Link to comment https://forums.phpfreaks.com/topic/183904-file_exists-wont-activate-if-statement/#findComment-970822 Share on other sites More sharing options...
premiso Posted December 3, 2009 Share Posted December 3, 2009 Also this statement if($_GET["page"]=""||!isset($_GET["page"])){ Is incorrect, it should be: if (!isset($_GET["page"]) || $_GET["page"] == ""){ A: you put the isset first, because if the variable is not set, there is nothing in it to test and will cause a notice error. B: you have 1 equals sign comparing the $_GET to "", that just assigns the $_GET to be "". So changing that to == fixes that issue as that is the comparison operator. Link to comment https://forums.phpfreaks.com/topic/183904-file_exists-wont-activate-if-statement/#findComment-970831 Share on other sites More sharing options...
cgimusic Posted December 3, 2009 Author Share Posted December 3, 2009 Also this statement if($_GET["page"]=""||!isset($_GET["page"])){ Is incorrect, it should be: if (!isset($_GET["page"]) || $_GET["page"] == ""){ A: you put the isset first, because if the variable is not set, there is nothing in it to test and will cause a notice error. B: you have 1 equals sign comparing the $_GET to "", that just assigns the $_GET to be "". So changing that to == fixes that issue as that is the comparison operator. Thank you. I completely forgot that == is the comparison operator. I said it would be a stupid mistake. Link to comment https://forums.phpfreaks.com/topic/183904-file_exists-wont-activate-if-statement/#findComment-970835 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.