I am creating my first (basic) php application and would like to start as I mean to go on as regards file paths and globals - this is quite new to me. WHat I have now works however I would like to be advised if there is a more efficient way (for future-proofing/expansion)
I have a simple file structure as follows;
- css
-- bootstrap.css
- lib
-- display.php
- template
-- header.php
-- footer.php
- admin
-- login.php
- globals.php
- index.php
I would like to include my css (bootstrap.css
) on each page. I have declared a single global in my global.php
as follows;
<?php define('URL', 'http://localhost/myLocalSite'); ?>
The in my display.php
I have included the css;
<link href="<?php echo URL ?>css/styles.css" rel="stylesheet">
<link href="<?php echo URL ?>css/bootstrap.min.css" rel="stylesheet">
I include these in my index.php
by using the following;
<?php include('globals.php') ?>
<?php include('template/header.php') ?>
<?php include('lib/display.php') ?>
I include these in my login.php
by using the following (not the sub-folder location);
<?php include('../globals.php') ?>
<?php include('../template/header.php') ?>
<?php include('../lib/display.php') ?>
Whenever working in a file within a sub-directory (as above login.php
) do I always need to include the ../
in order to include the files or is there a better way?
Like I say it works and I am new to this so ay advice is appreciated.