• Sign in to Neowin Faster!

    Create an account on Neowin to contribute and support the site.

  • 0
Sign in to follow this  

PHP Error

Question

Lil' J    0

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

Share this post


Link to post
Share on other sites

7 answers to this question

Recommended Posts

  • 0
destrux    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;

Share this post


Link to post
Share on other sites
  • 0
uniacid    0

Yeah I saw that, you should have the brackets, did you try it with them?

Share this post


Link to post
Share on other sites
  • 0
KeyStorm    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

Share this post


Link to post
Share on other sites
  • 0
GatorV    1

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;

Share this post


Link to post
Share on other sites
  • 0
Seth    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;

Share this post


Link to post
Share on other sites
  • 0
Lil' J    0

Thank you all for your help, it was the code by Seth Kinast that worked.

Share this post


Link to post
Share on other sites
  • 0
Michael_C    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;

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.