views:

31

answers:

3

Hello to everyone, I'm a newbie that really needs help, been trying to make this php script work with no luck, when I'm running the site locally it works but after I move the files to the server Im getting the following error, hope someone can help me:

Warning: include(/var/chroot/home/content/16/5976816/html/inc/header.php) [function.include]: failed to open stream: No such file or directory in /home/content/16/5976816/html/vtr/test/index.php on line 49

This is the scrip that I'm using:

<?php

    // Include the header:
    include($_SERVER['DOCUMENT_ROOT'] . '/inc/header.php');

    ?>

    <div id="contents">
        <div id="content">

            <?php
            // Define our array of allowed $_GET values
            $pass = array('intro','about','vincent-tran','philip-roggeveen','estate-planning','criminal-case','personal-injuries','bankruptcy','inmigration','deportation','family-law','litigation','corporations-and-llcs', 'payments','consultation','request-callback','contact-us');
            // If the page is allowed, include it:
            if (in_array($_GET['id'], $pass)) {
                include ($_SERVER['DOCUMENT_ROOT'] . '/inc/' . $_GET['id'] . '.php');
            }
            // If there is no $_GET['id'] defined, then serve the homepage:
            elseif (!isset($_GET['id'])) {
                include ($_SERVER['DOCUMENT_ROOT'] . '/inc/intro.php');
            }
            // If the page is not allowed, send them to an error page:
            else {
                // This send the 404 header
                header("HTTP/1.0 404 Not Found");
                // This includes the error page
                include ($_SERVER['DOCUMENT_ROOT'] . '/inc/error.php');
            }
            ?>

        </div>
    </div>
    <!-- end OutsideWrap-->

    <?php
    // Include the footer:
    include($_SERVER['DOCUMENT_ROOT'] . '/inc/footer.php');
    ?>
A: 

The error shows that the file you want to include could not be found.

Make sure that:

  • you are specifying the correct path
  • directory has right permissions, chmod to 755

You can check the resolved path by echoing it:

echo $_SERVER['DOCUMENT_ROOT'] . '/inc/header.php';

And as far as I can remember, you don't need / after $_SERVER['DOCUMENT_ROOT']

Sarfraz
A: 
 if (strpos($system_folder, '/') === FALSE)
{
    if (function_exists('realpath') AND @realpath(dirname(__FILE__)) !== FALSE)
    {
        $system_folder = realpath(dirname(__FILE__)).'/'.$system_folder;
    }
}
else
{
    // Swap directory separators to Unix style for consistency
    $system_folder = str_replace("\\", "/", $system_folder); 
}

here's a function that gets the base directory of your application

just replace $system_folder with your site's folder name like if that is on htdocs/somewebapp

$systemfolder = "somewebapp";
lock
A: 

Thank you guys for all your help, I wasn't using the correct path.

<?php

            // Define our array of allowed $_GET values
            $pass = array('intro','about','vincent-tran','philip-roggeveen','estate-planning','criminal-case','personal-injuries','bankruptcy','inmigration','deportation','family-law','litigation','corporations-and-llcs', 'payments','consultation','request-callback','contact-us');
            // If the page is allowed, include it:
            if (in_array($_GET['id'], $pass)) {
                include ($_SERVER['DOCUMENT_ROOT'] . '/vtr/today/inc/' . $_GET['id'] . '.php');
            }
            // If there is no $_GET['id'] defined, then serve the homepage:
            elseif (!isset($_GET['id'])) {
                include ($_SERVER['DOCUMENT_ROOT'] . '/vtr/today/inc/intro.php');
            }
            // If the page is not allowed, send them to an error page:
            else {
                // This send the 404 header
                header("HTTP/1.0 404 Not Found");
                // This includes the error page
                include ($_SERVER['DOCUMENT_ROOT'] . '/vtr/today/inc/error.php');
            }
            ?>

Now is working just fine.

Luis Martinez