Hey guys,
Im in the middle of making a website and trying to learn php as i go. Ill try to explain as clearly as i can, but for those who want to cut to the chase, how do i do a php include from a subfolder, calling a file from the root directory?
The long winded version: Ive got a site in the following structure:
index.php
header.php
footer.php
products/page1.php
products/page2.php
products/page3.php
style.css
My header.php includes the following:
<head>
<link rel="icon" href="favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="style.css" type="text/css" media="all">
<title><?php echo $title; ?></title>
<meta name="title" content="<?php echo $metatitle; ?>">
<meta name="description" content="<?php echo $description; ?>">
<meta name="keywords" content="<?php echo $keywords; ?>">
</head>
So, in my index.php i have:
<?php
$title ="Insert title here";
$metatitle ="Insert title here";
$description ="Insert description here";
$keywords ="example, key, word, here";
include ('header.php');
Thats great and works well. But when i tru to do the same from products/page1.php, i get a whole load of problems because the include is looking in the wrong place. I can kinda get it working by using include('../header.php') - but that doesnt apply my css, as that loads the header.php allright, but then just looks for the css in products/style.css! So, i kinda understand what is going on, but i dont know how to fix it.
Ive been searching loads, and ive seen something like DOCUMENT_ROOT, which i think could work, but i dont know the actual code to use it. Im thinking, something like
<head>
<link rel="icon" href="[DOCUMENT_ROOT]/favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="[DOCUMENT_ROOT]/style.css" type="text/css" media="all">
<title><?php echo $title; ?></title>
<meta name="title" content="<?php echo $metatitle; ?>">
<meta name="description" content="<?php echo $description; ?>">
<meta name="keywords" content="<?php echo $keywords; ?>">
</head>
But when i tried that on my XAMPP test server, firefox read it as C:\XAMPP\style.css - and was unable to load it?!
So, what on earth can i do?
Cheers for any help. Seriously, im really getting annoyed by this and any help would be greatly appreciated.