Errors with file hierarchy

Hi all, very glad to find you here. I have what may be a silly question, but all the same, I can not for the life of me solve this issue.

It is going to be a little tricky to explain I think, but I will try. I am brand new to PHP, quite handy with html/css.

So what I want to do:
I have my index.php, from there I have a link to a page (educational.php), which contains all of my educational links, one of which is a dictionary with separate pages for each letter.

I want my “path” for the letter “A” to be:
alexrowsell.com/educational/dictionary/a.php

but all of my includes (header, advertising, footer) break as soon as I try to build the hierarchy. They broke as soon as I tried to build the first level down (ie: alexrowsell.com/educational/dictionary.php).

This domain is my test-bed. In order to make everything work, I put every file in the root, with a “scripts” folder containing the files I use in my includes, and a “styles” folder containing my css. With everything in the root it works, but I don’t want it to be alexrowsell.com/a.php, nor alexrowsell.com/dictionary.php, but instead I want a sensible path.

In my header.php include is my stylesheet link, my doctype etc etc, and my footer.php closes my container div and body. I really don’t wanna put all of the redundant information on every page…

Am I reaching? Is it do-able? Please let me know if you need more info or anything else.

If your root is one level down then use [php]…/[/php]

You will have to test if the header is there then go up a folder if not with something like this you can add other files when its found

if( (file_exists('header.php') ){ include_once('header.php'); include_once('footer.php'); }else if( (file_exists('../header.php') ){ include_once('../header.php'); include_once('../footer.php'); }else{ include_once('../../header.php'); include_once('../../footer.php'); }

Thank you both for taking the time to reply, I will test and see. My brain had shut off by the time I quit last night, so I am hoping today will work better!

Spring: I am probably doing something wrong, but simply adding the appropriate number of …/ for how many levels down I am is not working.

Noodles: I am getting a syntax error

(Parse error: syntax error, unexpected ‘{’ in /home/alexrows/public_html/educational/farrierdictionary.php on line 4)

with the code you provided, copied and pasted. Shown below how I have it in my document.

[php]<?php
$subtitle = “Dictionary of Farriery”;
if( (file_exists(‘scripts/header.php’) ){
include_once(‘scripts/header.php’);
}else if( (file_exists(’…/scripts/header.php’) ){
include_once(’…/scripts/header.php’);
}else{
include_once(’…/…/scripts/header.php’);
}
?>[/php]

What did I do wrong?

Thanks again for all of your help!

Go to this page and look at line 4
/home/alexrows/public_html/educational/farrierdictionary.php

What’s up with the extra parenthesis?
[php]<?php
$subtitle = “Dictionary of Farriery”;
if( file_exists(‘scripts/header.php’) ){
include_once(‘scripts/header.php’);
}else if( file_exists(’…/scripts/header.php’) ){
include_once(’…/scripts/header.php’);
}else{
include_once(’…/…/scripts/header.php’);
}
?>[/php]

I copied the code directly from Noodles’ post, only removing the include for the footer (as i need my footer at the bottom…).

I don’t know PHP syntax well enough to see extra anything; as long as I see opening and closing parentheses, I assume things are all good. Where is there an extra?

Copy the code I posted above. I removed them.

Ah ha! I see them now.

Ok. That pulled the header. But not my stylesheet?

alexrowsell.com/educational/farrierdictionary.php

(please disregard everything below the header, I’ll fix the rest after I get this figured out)

http://alexrowsell.com/educational/styles/horseshoes.css

That dir doesn’t exist, you probably need to use …/ again.

BTW, if you made a base_url variable you wouldn’t have had any problems.

Haha, I figured that I must have made some foolish mistake at the beginning that made my life much more difficult.

I am going to figure out how to make a base_url, and what it does/how it works now. Thanks again.

Great! I got my stylesheet to exist. Thanks for that. When I go to the next level down (alexrowsell.com/educational/dictionary/a.php) will I need to edit my header to have my stylesheet link read:

../../styles/horseshoes.css ?

I’m sorry I am harassing, I really do appreciate your help.

I cannot find a tutorial or any direction on how to make and use a $base_url. I am assuming it would be easy to create:

[php]$base_url = ‘http://domain.com’;[/php]

But how and where would I use it? How would it have negated all of these foolish hoops I’ve made for myself to jump though?

And, where would the $base_url definition “live”? Oy vey, I’m floundering.

So if you want include a a file

[php]include_once($baseurl.‘script/header.php’);[/php]

@spring
You have never ever made a mistake then in your life?
Thats what I thought!

Thank you Noodles. I thought I may have annoyed the forum by asking another question in this thread so I started a new thread with the $base_url question. It has been answered, thanks again for all your help.

???
What the hell are you talking about?

Sponsor our Newsletter | Privacy Policy | Terms of Service