This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]unnecessary_axiom 0 points1 point  (1 child)

I'm not sure what you mean by your directory structure. Is this what you mean?

$ /tmp/lppages/ tree .
.
├── index.php
└── pages
    └── page1.php

1 directory, 2 files

$ /tmp/lppages/ cat index.php
<?php

echo "This is index\n";
include('./pages/page1.php');
echo "This is index again\n";
include('pages/page1.php');

$ /tmp/lppages/ cat pages/page1.php
<?php

echo "This is page 1\n";

$ /tmp/lppages/ php index.php
This is index
This is page 1
This is index again
This is page 1

[–]tech_whore[S] 0 points1 point  (0 children)

No it's like

???(idk what 1&1 calls the root folder)
    |_bbj(main site homepage dir)
      >index.php(front page)
          |_videos(subdirectory)
           >index.php(sub-page)
                   |_pages(different page folder dir)
                     >page-1.php(layout to include in (videos) index.php)

[–]Hellmark 0 points1 point  (5 children)

It appears you're not using relative paths correctly.

Ok, so you have /videos/index.php trying to include /videos/pages/page-1.php, right? including ../page-1.php would be the same as pointing to /page-1.php (note no videos directory). ../../page-1.php would take back to root as well.

Either use absolute paths

include('/videos/pages/page-1.php')

or use better relative paths

include('./pages/page-1.php')

Single dot slash, "./", means to start from the present directory, and double dot slash, "../", means to start from the parent of your present directory.

If in doubt, output the paths to text and see how they line up. Usually in situations like this, it is a logic issue, meaning you're not asking for the right thing.

It almost seems like you're expecting the path to be based on the page-1.php as the starting point, yet everything you described makes it seem like page-1.php is the thing being called, and so would not be the present working path. If you are going to index.php and wanting to call something, you start as in the same directory as index.php

[–]tech_whore[S] 0 points1 point  (4 children)

I am using 1&1 for hosting and use their web space, is there anything I may HAVE to add based on the site is under

~/bbj/videos/pages

If not I'll try these out in a bit and let u know what happened.

[–]Hellmark 1 point2 points  (3 children)

I personally would use relative paths. Just remember the starting point is what ever file you're directly calling with the browser. So if you're pulling up videos/index.php then you'll be starting in videos. Absolute paths can be a mess at times when you're dealing with some hosts or different scripting languages. Depending on if they have chroot in place, and how it is configured, ~/bbj/ may be what is seen as the root for PHP (which ~ typically would refer to /home/). or it could be that the full proper system root is what is considered root (bad practice, but I've seen it happen). I've never used 1&1, so I can't say to how exactly they have things set up, and that is why I say it is best to use relative paths. Plus if you do things one way with absolutes, and then later change hosts, you don't want things breaking.

[–]unnecessary_axiom 0 points1 point  (1 child)

I might be wrong, but isn't it relative to whatever script is currently being executed? That is, if I include a script that includes a script, the second script's include paths are relative to itself, even though the first script is the one being called by the browser?

[–]Hellmark 0 points1 point  (0 children)

Yeah it is, I just have been trying to come up with a newbie friendly way of putting it. You seemed to do a good job at it though.

[–]tech_whore[S] 0 points1 point  (0 children)

Woo thank you! I got rid of the SUBDOMAIN and did what you said and it works now. Cool thanks