Thursday, 12 September 2013

PHP relative paths using home web server throwing errors

PHP relative paths using home web server throwing errors

I'm using XAMPP on my home machine and also using it as a web server.
I have a main folder which is for my site, I then have a dev folder where
I'm trying to work on a new site. (not sure if this is relevant info but
worth mentioning)
On my local machine the site is c:/MySite/Dev within Dev I have something
along the lines of
Dev assets css js includes footer header core init folder subfolder
files.php index.php
init is included at the top of every page, header and footer includes are
also included. Within header is my nav bar.
I'm trying to define a site root so that I don't have to keep changing ../
and ../../ etc depending on the location of the files.
Also, seeing as my header gan be in many subfolders, the links to main
index etc can get messy as index.php from a subfolder won't take me to the
root index.php
I've tried using DIR and SERVER_ROOT bt of which I couldn't get to work
properly, server root returned the c:/www and DIR returned the folder of
the file in which it was called.
I'm still new to php so learning as I go.
This is what I've tried:
in init:
define("WEB", "http://mySite.com/Dev");
$environment = WEB;
echo $environment;
this works in the first instance, then when I'm in the subfolder and try
using the home link I get :
http://mySite.com/Dev/Folder/Subfolder/%3Cbr%20/%3E%3Cb%3ENotice%3C/b%3E:%20%20Undefined%20variable:%20environment%20in%20%3Cb%3EC:/www/Dev/includes/header.php%3C/b%3E%20on%20line%20%3Cb%3E38%3C/b%3E%3Cbr%20/%3E/index.php
can anyone help please?

No comments:

Post a Comment