Maarten
Maarten

Reputation: 17

Include does not work on index file

I have a little problem with including files. I have two pages where i use exactly the same starting 10 rows.

    <html>
    <head>
    <?php include "../~13097377/include/head.html"; ?>
    </head>
    <body id="body" >
    <div style="background-color: #E0ECF8; min-height: 100%;">
    <div style="position:fixed; background-color: #E0ECF8;">
    <?php include "../~13097377/include/slideshow.html"; ?>
    <?php include "../~13097377/include/menu.html"; ?>
    <div style="padding: 0px 20px 0px 20px;">

http://eduweb.hhs.nl/~13097377/index.php
http://eduweb.hhs.nl/~13097377/contact/contact.php

The contact page reacts normal but the index page gives a lot of errors like "failed to open stream: No such file or directory in /var/www"

Does someone know how to fix this?

Upvotes: 0

Views: 131

Answers (3)

jeroen
jeroen

Reputation: 91734

Relative paths are not going to work when your files are in different levels of directories. You can use an absolute path, relative to the root of the web-server:

<?php include $_SERVER['DOCUMENT_ROOT'] . "/~13097377/include/slideshow.html"; ?>
<?php include $_SERVER['DOCUMENT_ROOT'] . "/~13097377/include/menu.html"; ?>

Upvotes: 1

Ennui
Ennui

Reputation: 10190

Change all instances of ?php include to <?php include.

All PHP code should be between <?php opening and ?> closing tags.

Once you fix the syntax errors, check on your include paths. They are probably relative but may not be depending on webserver and PHP configuration.

Upvotes: 0

Marc B
Marc B

Reputation: 360662

You're using a relative path, ../etc... in your include, which means the path being checked is RELATIVE to the location of the script you're running the include directive from.

That means, assuming your document root is /var/www/site/html

/var/www/site/html/index.php           -> /var/www/site/~13097377/include/head.html
/var/www/site/html/contact/contact.php -> /var/www/site/html/~13097377/include/head.html

Unless you have a ~13097377 directory in BOTH your doc_root and doc_root/contact directories, this is why you get your errors. You're telling PHP to look for your file in a place that doesn't exist.

Upvotes: 1

Related Questions