• 0

PHP Error


Question

PHP Error

Warning: main(.php): failed to open stream: No such file or directory in /home/lilj/public_html/index.php on line 59

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

7 answers to this question

Recommended Posts

  • 0

Just a quick thought but in that example aren't you missing your brackets? Or would that even matter?

&lt;?php
if (isset($id)) {
  include ("$id.php");
} else {
  include ("home.php");
}
?&gt;

Link to comment
Share on other sites

  • 0

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

  • 0

change it like this to prevent the errors:

&lt;?php
    if(!empty($id)) //You can change the id to anything you like.
    include("$id.php");
    else
    include("home.php"); //Default page
  ?&gt;

Link to comment
Share on other sites

  • 0

No, no. You guys are checking the source rather than the product. Use this:

&lt;?php
  if(file_exists($id . '.php')) {
    include($id . '.php');
  } else {
    include('home.php'); // Default page
  }
?&gt;

Link to comment
Share on other sites

  • 0

Or if you want to keep the double quotes:

&lt;?php
    if(isset($id)) //You can change the id to anything you like.
        include "{$id}.php";
    else
        include "home.php"; //Default page
  ?&gt;

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.