Jump to content

How to make include() function work on localhost.


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.


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 ?

Link to comment
Share on other sites

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''); ?>


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

Edited by JIXO
Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • 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.