Lyuri Posted August 17, 2010 Share Posted August 17, 2010 Hello there. I used this code so many times long ago, but I still don't remeber and don't know what I'm doing wrong. http://circus.ka-blooey.net/ If I try to click on any link below the post, I got the error: Warning: include(.php) [function.include]: failed to open stream: No such file or directory in /home/kablooey/public_html/circus/index.php on line 5 Warning: include(.php) [function.include]: failed to open stream: No such file or directory in /home/kablooey/public_html/circus/index.php on line 5 Warning: include() [function.include]: Failed opening '.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/kablooey/public_html/circus/index.php on line 5 -----------------------x My index is: <?php include("header.php"); ?> <? if (empty($_GET["boo"])) {$boo="news/show_news";} include "$boo.php"; ?> <?php include("footer.php"); ?> and the footer, where the links are is: <br /> <div id="menu"><center><a href="http://circus.ka-blooey.net">clear</a> ---x--- <a href="?boo=out">links out</a> ---x--- <a href="?boo=credits">credits</a></center></div><br /> <br /> <br /> <div id="footer"><img src="http://circus.ka-blooey.net/layout/circus_footer.jpg" /></div> </div> </div> </div> </body> </html> Help please? =/ Quote Link to comment https://forums.phpfreaks.com/topic/210913-failed-to-open-stream-noob-question/ Share on other sites More sharing options...
MasterK Posted August 17, 2010 Share Posted August 17, 2010 <? if (empty($_GET["boo"])) {$boo="news/show_news";} include "$boo.php"; ?> You have the condition for If the Boo GET variable is empty, but your not telling it what to do if its NOT Empty Quote Link to comment https://forums.phpfreaks.com/topic/210913-failed-to-open-stream-noob-question/#findComment-1100110 Share on other sites More sharing options...
Pikachu2000 Posted August 17, 2010 Share Posted August 17, 2010 Try this instead. <?php include("header.php"); if (empty($_GET['boo'])) { $boo="news/show_news"; } include $boo . '.php'; include("footer.php"); ?> // If the result is the same, add this to the head of the script to see what values the $_GET array holds echo '<pre>'; print_r($GET); echo '</pre>'; Quote Link to comment https://forums.phpfreaks.com/topic/210913-failed-to-open-stream-noob-question/#findComment-1100113 Share on other sites More sharing options...
Lyuri Posted August 17, 2010 Author Share Posted August 17, 2010 @MasterK: umh.. It didn't worked. Actually it started to give me the same error on the main page too. and if it's not empty, probably a link will lead to there, right? @Pikachu2000: I still get the error. But didn't understand where should I put this code: echo '<pre>'; print_r($GET); echo '</pre>'; You mean in the header.php or inside the index.php in anywhere? =/ Quote Link to comment https://forums.phpfreaks.com/topic/210913-failed-to-open-stream-noob-question/#findComment-1100120 Share on other sites More sharing options...
Pikachu2000 Posted August 17, 2010 Share Posted August 17, 2010 You can put it right under the opening <?php tag. It's just to do some basic debugging, then you can post the output from it here. Quote Link to comment https://forums.phpfreaks.com/topic/210913-failed-to-open-stream-noob-question/#findComment-1100130 Share on other sites More sharing options...
Lyuri Posted August 17, 2010 Author Share Posted August 17, 2010 Umh.. I did put it there, but it didn't give me any feedback, anything new =/ Still just show the error. By the way, I got to go now. And if I can't fix it by this week I'll just use the normal links, it doesn't really matter for me. Just wanted to see what was wrong and all. (And I do prefer this kind of link, but anyway) I'll be back tomorrow and try to see if I can do anything more. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/210913-failed-to-open-stream-noob-question/#findComment-1100132 Share on other sites More sharing options...
PFMaBiSmAd Posted August 17, 2010 Share Posted August 17, 2010 The problem that MasterK pointed out still exists. If the $_GET variable IS set you need to set $boo to it so that the include statement that is using the $boo variable will have the correct value in it. Quote Link to comment https://forums.phpfreaks.com/topic/210913-failed-to-open-stream-noob-question/#findComment-1100134 Share on other sites More sharing options...
JasonLewis Posted August 17, 2010 Share Posted August 17, 2010 Think about this, if a user didn't click a link you want to display a default page, however if they have clicked a link you want to show them the page they clicked. Provide more error checking. if(!isset($_GET['boo'])){ // they didn't click a link, show default page $boo = 'news/show_news'; }else{ // a link was clicked, set the variable to the $_GET value $boo = $_GET['boo']; } // now do some error checking if(!file_exists($boo . '.php')){ // the page they requested could not be found, show a 404 error. you'll have to make this 404.php page include('404.php'); }else{ // the page exists, we can show it to the user include($boo . '.php'); } It's exactly what MasterK was talking about, however you should also check that the page exists like above. Quote Link to comment https://forums.phpfreaks.com/topic/210913-failed-to-open-stream-noob-question/#findComment-1100135 Share on other sites More sharing options...
MasterK Posted August 17, 2010 Share Posted August 17, 2010 @MasterK: umh.. It didn't worked. Actually it started to give me the same error on the main page too. and if it's not empty, probably a link will lead to there, right? Yea, after I posted I realised it was wrong I'm still learning Anyways, Here is how I would do it, Might not be the best way but it works... <?php include("header.php"); if (empty($_GET['boo'])) { $boo="news/show_news"; } else { $boo = $_GET['boo']; } include $boo . '.php'; include("footer.php"); ?> Posted at the same time as ProjectFear, but What he said Quote Link to comment https://forums.phpfreaks.com/topic/210913-failed-to-open-stream-noob-question/#findComment-1100136 Share on other sites More sharing options...
Pikachu2000 Posted August 17, 2010 Share Posted August 17, 2010 That part got right past me somehow . . . You have the condition for If the Boo GET variable is empty, but your not telling it what to do if its NOT Empty Quote Link to comment https://forums.phpfreaks.com/topic/210913-failed-to-open-stream-noob-question/#findComment-1100137 Share on other sites More sharing options...
Lyuri Posted August 17, 2010 Author Share Posted August 17, 2010 Oh, it worked! Used ProjectFear code, but now I got what MasterK said. The index couldn't show the page when it wasn't empty. Sorry guys! Thanks everyone :3 Quote Link to comment https://forums.phpfreaks.com/topic/210913-failed-to-open-stream-noob-question/#findComment-1100440 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.