PHP doesn't work

I have researched blogs and forums so much and cannot find a solution to this problem. I am using the Wamp directory: C: \ wamp \ bin \ apache \ apache2.4.9 \ htdocs \ lr

The lr at the end of / htdocs is just the folder where I store my webpage.

Code inside my index.php:

<html>
<?php include('includes/head.php'); ?>
<body>
    <?php include 'includes/header.php'; ?>
    <div id="container">
        <?php include 'includes/aside.php'; ?>
    </div>
    <footer>
        &copy; phpacademy.org 2011. All rights reserved.
    </footer>
</body>

      

When I load index.php in chrome or any browser, the only thing I see is the footer, which turns out to be the only thing that is NOT configured in the php include tag.

Here is the code inside my head.php

<head>
<title>Website Title</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="css/screen.css">

      

Very simple code that only scares me why it doesn't work. If you would like more examples of the code that I am using, let me know. I am happy to provide some as I really need it in order to continue building the database for my registration / registration page.

+3


source to share


3 answers


PHP probably doesn't find any files to include.

Are you sure the "includes" folder is in the same directory as index.php?



Also, I would suggest using "** / ** includes / ..." with a forward slash at the beginning to make sure it is looking for included files from the root directory and not from the relative path of your index.php.

Also, shouldn't your root be C: \ wamp \ www \ in WAMP?

+3


source


Try to close the main tag first in your head, include the file, if that doesn't work, I'll dig deeper: D

EDIT:
Sometimes there are file path problems. I usually use:

<?php include $_SERVER['DOCUMENT_ROOT']."/filename.php";?>

      



In your case, it would probably be:

<?php include $_SERVER['DOCUMENT_ROOT']."/lr/includes/header.php";?>

      

0


source


You can check if the included file exists, this might let you know what is going on

if(file_exists('includes/head.php')):
    include 'includes/head.php';
else: 
   echo 'file either not readible or does not exist';
endif;

      

0


source







All Articles