Jump to content

failed to open stream (noob question)


Lyuri

Recommended Posts

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? =/

Link to comment
https://forums.phpfreaks.com/topic/210913-failed-to-open-stream-noob-question/
Share on other sites

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>';

@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? =/

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!

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.

@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  :P

 

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  :D

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.