/    Sign up×
Community /Pin to ProfileBookmark

Linking to PHP Inlcude Issue

I am having issues with my logo not showing up properly when using Include across multiple directories. You can see it here: http://pachecorottweilers.com/new_rott/litters/captain_beauty2019/captain_beauty_2019_litter.php

Folder Structure: Root – Resources – Include
This is the code I use for the main pages like Home, About, FAQ, Contact, etc. and this works properly
<?php include(‘resources/include/navigation.php’); ?>

The Breeder that I am building this site for has multiple dog litters so I am putting all of the litters in their own Litter Folder to help keep the root clean

Folder Structure: Root – Litter – Captain_beauty_litter
Included in this is a Logo and Menu. The menu shows up properly but the Image does not.
<?php include(‘../../resources/include/navigation.php’); ?>

I have been researching how to fix this but have been unsuccessful as my PHP knowledge is very limited as you can see. But I saw some things on specifying a ROOT DIRECTORY with PHP but couldn’t figure it out.

Any help would be greatly appreciated… THANK YOU!

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@ginerjmMar 09.2019 — You are describing your folder structure yet the url that you show at the beginning doesn't match it at all. I am confused.

Your include is using a relative path. You need to make sure that it is accurate obviously.


One way could be to get the document root from the $_SERVER array and append your relative paths to it when creating a full path.

$root = $_
SERVER['DOCUMENT_ROOT'];

include($root . '/resources/include/navigation.php');
Copy linkTweet thisAlerts:
@fireproofgfxauthorMar 10.2019 — I have all of my resources such as CSS, JS, and Includes in the Resource Folder and the html pages in the Root. I don't want all of the dog litters and pages in the main root since she has a lot of dogs so I have put them in their own folder Root - Litter - Littername (folder) LitterHTML

I have seen people recommend to use

$root = $SERVER['DOCUMENT_ROOT'];

include($root . '/resources/include/navigation.php');

But I wasn't sure how to do it since I don't know much about PHP.

Is there a certain spot I should put that array on each page and for each include? Or do you just do the array at the top of the page and then the includes



Copy linkTweet thisAlerts:
@rootMar 10.2019 — 
  • 1. Seperate JavaScript, Css and PHP includes...


  • You should not put server-sides in to a folder that is public that you include in a script, its just tidier, you know that a specific folder is server scripts and you can use the server permissions to hide from public scrutiny any directory listing requests.

  • 2. As ginerjm has pointed out, you need to work with the file path structures so that they work.


  • If your server does not resolve relative paths then you have to tell the script the actual path as the path could be a symlink of some sorts and then things start to get hairy.

    It is often good practice to use real paths that the script has worked out and then you can append the relative paths you use to the basepath that has been calculated.

    You calculate the base path for a couple of reasons, first, the host can reconfigure their schemes over night and then you can end up with a nobbled site (not working) or you move domain and its then not working because that host uses a path system that hides the true path and then your unable to link directly...

    Let the system tell you where your domain is on the server in terms of its actual path.

    if you are really clever, you could write the code to speed up the process by setting a path to use and when there is an error, work out what the path is and if it has changes, update the path.

    ?
    Copy linkTweet thisAlerts:
    @ginerjmMar 10.2019 — Not sure what you mean when you refer to "array".

    As I have shown you - set the $root variable at the top of every script you call. Then use it wherever you need to point to something relative to it. I don't care what or where you store things - that's your problem as Root has pointed out to you. He is correct tho when he says not to store major php code in the root folder or an accessible one below it. Personally I use the php folder that exists beside the root folder (at the same level) so that it is outside the public area of your domain. And for that I use a different variable to reference that php folder as in:

    $root = $_SERVER['DOCUMENT_ROOT'];

    $php_path = $root . '/../php';

    ..

    ..

    include $php_path . '/myphpscript.php';
    Copy linkTweet thisAlerts:
    @fireproofgfxauthorMar 10.2019 — Guys I am truly thankful for your time and input on this. Thank your for your patience to. Ginerjm, I mentioned array because you had mentioned it on your first comment so that is what I thought it was called. Sorry for the confusion. I am totally a noob when it comes to PHP and really only use it for Includes which come in hand for replicated multiple pages of content. which usually works for me like this: <?php include('resources/include/navigation.php'); ?> I understand we have to do something different in order to direct php in the right direction since the include file is 2 down from the root and the Litter Page is 2 up from the root if that makes sense.

    Based off of what you said this is was what I added to the website for the menu navigation and it still doesn't work.
    <i>
    </i> &lt;?php $root = $SERVER['DOCUMENT_ROOT'];
    include($root . '/resources/include/navigation.php'); ?&gt;

    You can see it here: http://pachecorottweilers.com/new_rott/litters/captain_beauty2019/captain_beauty_2019_litter.php

    *(Added [code] tags ~ Mod)*
    Copy linkTweet thisAlerts:
    @ginerjmMar 10.2019 — Look up in the manual for how to enable php error checking and you MIGHT get the error message that will tell you what is wrong with this code.
    Copy linkTweet thisAlerts:
    @NogDogMar 11.2019 — The built-in super-global variable is $_SERVER, not $SERVER.
    ×

    Success!

    Help @fireproofgfx spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.8,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...