chinrest Posted May 17, 2007 Share Posted May 17, 2007 "Cut-n-paste" programmer here--go easy on me. I've used this code before, but it does not work on my current host (Dreamhost): <?php $invalidChars=array("/",".","\\","\"",";"); $page=str_replace($invalidChars,"",$page); include ("pages/".$page.".html"); ?> When I call index.php?page=home, I get this is the error message: Warning: include(.html) [function.include]: failed to open stream: No such file or directory in /home/user/domain/dev/index.php on line 44 Warning: include() [function.include]: Failed opening '.html' for inclusion (include_path='.:/usr/local/php5/lib/php') in /home/user/domain/dev/index.php on line 44 If I replace the $page variable with an actual file, and call index.php in the browser, it works fine: <?php $invalidChars=array("/",".","\\","\"",";"); $page=str_replace($invalidChars,"",$page); include ("pages/home.html"); ?> Any help? Quote Link to comment https://forums.phpfreaks.com/topic/51846-beginner-help-please-includes/ Share on other sites More sharing options...
taith Posted May 17, 2007 Share Posted May 17, 2007 what do you get when you echo $page...? Quote Link to comment https://forums.phpfreaks.com/topic/51846-beginner-help-please-includes/#findComment-255503 Share on other sites More sharing options...
Garath531 Posted May 17, 2007 Share Posted May 17, 2007 Where is $page defined? Quote Link to comment https://forums.phpfreaks.com/topic/51846-beginner-help-please-includes/#findComment-255512 Share on other sites More sharing options...
kenrbnsn Posted May 17, 2007 Share Posted May 17, 2007 You have assumed that register_globals are enabled. While this used to be true many years ago, you can not and should not assume it anymore. Change your code to explicitly reference the appropriale superglobal array, in your case "$_GET". <?php $invalidChars=array("/",".","\\","\"",";"); $page=str_replace($invalidChars,"",$_GET['page']); include ("pages/".$page.".html"); ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/51846-beginner-help-please-includes/#findComment-255516 Share on other sites More sharing options...
chinrest Posted May 17, 2007 Author Share Posted May 17, 2007 Thanks Ken. I really appreciate your help--Garath and Taith too, for your timely responses. Quote Link to comment https://forums.phpfreaks.com/topic/51846-beginner-help-please-includes/#findComment-255539 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.