Jump to content

How to make include() function work on localhost.


justin7410

Recommended Posts

Hey guys,

 

i am working for the first time on a localhost.

 

at the moment i have an index file and i want to start splitting the page up to make this website dynamic.

 

at first i tried to take my <head>.( <meta> / <title> tags , ) and include() them with a header.php file

 

I am not sure if this is something i can even do or if my path is just not correct.

 

i have my wamp on my C drive and its all through a www folder path.

 

i then created an include file inside the www, where all files that i would use dynamically would be placed( header, footer, etc..)

 

i tried two paths: 

include('include/header.php'); - didn't work

i then removed the folder and had all the php files in one folder.

include('header.php');

none of this works , the css of the page doesnt show up. i then replace the <head> info back inside the index, and all works fine.

 

any suggestions ?

It's always a good practice to set a document root, look here.

defined('SITE_ROOT'') ? NULL : define('SITE_ROOT', 'C:\Apache24\htdocs\project'');
// Or 
defined('SITE_ROOT'') ? NULL : define('SITE_ROOT', $_SERVER['DOCUMENT_ROOT'].'\project'');

Then refering to any file will be simple

require SITE_ROOT.'\includes\file.php';

As for the style sheets

.....
<?php defined('SITE_STYLE'') ? NULL : define('SITE_STYLE', SITE_ROOT.'\css''); ?>

<html>
...

<link rel="stylesheet" type="text/css" href="<?php echo SITE_STYLE.'\pagestyle.css';  ?>" />


Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.