Lil' J Posted March 16, 2005 Share Posted March 16, 2005 PHP Error Warning: main(.php): failed to open stream: No such file or directory in /home/lilj/public_html/index.php on line 59Warning: main(.php): failed to open stream: No such file or directory in /home/lilj/public_html/index.php on line 59 Warning: main(): Failed opening '.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/lilj/public_html/index.php on line 59 so... <?php if(isset($id)) //You can change the id to anything you like. include("$id.php"); else include("home.php"); //Default page ?> Any ideas anyone? Thanks in advance Link to comment Share on other sites More sharing options...
0 destrux Posted March 16, 2005 Share Posted March 16, 2005 Just a quick thought but in that example aren't you missing your brackets? Or would that even matter? <?php if (isset($id)) { include ("$id.php"); } else { include ("home.php"); } ?> Link to comment Share on other sites More sharing options...
0 uniacid Posted March 16, 2005 Share Posted March 16, 2005 Yeah I saw that, you should have the brackets, did you try it with them? Link to comment Share on other sites More sharing options...
0 KeyStorm Posted March 16, 2005 Share Posted March 16, 2005 Erm... you don't need the brackets if your assertion sequence is only one line, this works if(a) b; elseif(c) d; else e; The problem might be that there is no value in $id so it includes ".php" and that's probably not dound anywhere (neither in the relative folder nor in the PHP-defined include folder). Make sure you put something like $id = "xxx"; before that, where xxx is the name without extension of the php script you want to include Link to comment Share on other sites More sharing options...
0 GatorV Posted March 17, 2005 Share Posted March 17, 2005 change it like this to prevent the errors: <?php if(!empty($id)) //You can change the id to anything you like. include("$id.php"); else include("home.php"); //Default page ?> Link to comment Share on other sites More sharing options...
0 Seth Posted March 17, 2005 Share Posted March 17, 2005 No, no. You guys are checking the source rather than the product. Use this: <?php if(file_exists($id . '.php')) { include($id . '.php'); } else { include('home.php'); // Default page } ?> Link to comment Share on other sites More sharing options...
0 Lil' J Posted March 17, 2005 Author Share Posted March 17, 2005 Thank you all for your help, it was the code by Seth Kinast that worked. Link to comment Share on other sites More sharing options...
0 Michael_C Posted March 18, 2005 Share Posted March 18, 2005 Or if you want to keep the double quotes: <?php if(isset($id)) //You can change the id to anything you like. include "{$id}.php"; else include "home.php"; //Default page ?> Link to comment Share on other sites More sharing options...
Question
Lil' J
PHP Error
so...
Any ideas anyone?
Thanks in advance
Link to comment
Share on other sites
7 answers to this question
Recommended Posts