Hey guys n gals! New account here.. So hello everyone! Got a newbe question in PHP if any one can help.. lynx remote server & MAMP local on a
MacBook Pro.
I'm trying to create a php variable that specifies absolute path so I can always point to root so php items at different directory depths always work... Here is my file structure as it looks from root (dumbed down version so it's not so long):
public_html/
index.php
css/images/
includes/pages/config.php
This is my index.php file:
This is my my config.php file:
This is where my problem starts... when I want to use my /pages/about.php file the only way I can figure out how to get it to display correctly is by adding ../../ to the config.php require_once:
Maybe I'm misunderstanding PHP but do I have to call the:
<?php require_once( dirname(__FILE__) . 'config.php' ); ?>
on every page and if so, do I have to set the exact root directory on every page that is nested in by using ../ to back up in my file structure??
Note: I had a lot of trouble using $_SERVER['DOCUMENT_ROOT'] and I didn't like it. To many problem with some of my shared hosting accounts.
Also, not sure how to handle calling my CSS, JS, images, etc. IE normally I would call the style sheet using this in the head.php file:
How should I update this href="css/layout.css" (will be used on all pages) to PHP so the directory is always root.. and how do I update the images inside of the CSS document to always look into "images/file-name.jpg" rather than look into "/page/images/file-name.jpg" if it was called from "page/about.php"... ALSO considering that this layout.css file will be used for all pages, so it has to be a function thats supported across all of the pages..
Thats not all of my questions but I'll stop at that for now. baby steps right?
Any constructive help would be great. I might even be writing my PHP all wrong for all I know.
Thanks
MacBook Pro.I'm trying to create a php variable that specifies absolute path so I can always point to root so php items at different directory depths always work... Here is my file structure as it looks from root (dumbed down version so it's not so long):
public_html/
index.php
css/
- layout.css
includes/
- head.php
- header.php
- footer.php
- about.php
This is my index.php file:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php $thisPage="HOME";
require_once( dirname(__FILE__) . '/config.php' );
include (ABSPATH."includes/head.php");
include (ABSPATH."includes/header.php");?>
<div id="content-wrapper"><!-- Content --></div>
<?php include (ABSPATH."includes/footer.php"); ?>
This is my my config.php file:
Code:
<?php define( 'ABSPATH', dirname(__FILE__) . '/' ); ?>
This is where my problem starts... when I want to use my /pages/about.php file the only way I can figure out how to get it to display correctly is by adding ../../ to the config.php require_once:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php $thisPage="ABOUT";
require_once( dirname(__FILE__) . '../../config.php' );
include (ABSPATH."includes/head.php");
include (ABSPATH."includes/header.php");?>
<div id="content-wrapper"><!-- Content --></div>
<?php include (ABSPATH."includes/footer.php"); ?>
Maybe I'm misunderstanding PHP but do I have to call the:
<?php require_once( dirname(__FILE__) . 'config.php' ); ?>
on every page and if so, do I have to set the exact root directory on every page that is nested in by using ../ to back up in my file structure??
Note: I had a lot of trouble using $_SERVER['DOCUMENT_ROOT'] and I didn't like it. To many problem with some of my shared hosting accounts.
Also, not sure how to handle calling my CSS, JS, images, etc. IE normally I would call the style sheet using this in the head.php file:
Code:
<link rel="stylesheet" href="css/layout.css" type="text/css" media="screen" />
Thats not all of my questions but I'll stop at that for now. baby steps right?
Any constructive help would be great. I might even be writing my PHP all wrong for all I know.
Thanks