I am working on a project which will be connected to a MySQL database requires the following:
Two items available for those who log in:
My current site structure is as follows:
*Shortened* URL (project root folder): sois.com/440/finalproject/
This is an image of what you are supposed to see before LOGIN:
The code for /Home/index.php is as follows:
<?php # index.php
session_start();
//check session first
if (!isset($_SESSION['email'])){
include ('header.php');
}else
{
include ('header.php');
}
?>
<h2>Project Description</h2>
<h2>Blah Blah Blah ...</h2>
<h2>put images here if you want ...</h2>
<h2>change background ...</h2>
<h2>modify the site as you want ...</h2>
<?php
include ('footer.php');
?>
My question is fairly simply, I receive the errors:
Question: How can I properly link the file locations of header.php and footer.php (located in the include folder) so that my index.php (located in the Home folder) properly displays, like the above image?
While I know there are other posts floating around StackOverflow, I failed to locate one which I fully understood and could apply to my situation. I apologize if my question seems elementary but I fully appreciate any and all help!
Thanks everyone, if you have any further questions or need more details, let me know.
When you include files in PHP like you are currently doing (providing only the filename, such as header.php
), PHP will look in the same directory as the file currently being executed.
From I understand of your description (I struggled to understand the formatting), this is your directory layout within your document root (I've only shown the files important to this answer):
/home/index.php
/includes/header.php
/includes/footer.php
So, if you're in /home/index.php
, and you include 'header.php'
, PHP will assume that you're looking for the file located at /home/header.php
. What you need to do is tell PHP that you're looking in a different location.
In answer to your question, a good way of doing this is telling PHP to look relative to the current directory. This is how your includes would look afterwards:
include '../includes/header.php';
include '../includes/footer.php';
This basically tells PHP to go one level up from /home
(go into /
), enter into the includes
directory, and include the footer.php
or header.php
files.