Forum Moderators: coopster

Message Too Old, No Replies

problem with includes

minor problem with includes

         

liltman

7:01 pm on Aug 23, 2010 (gmt 0)

10+ Year Member



Hi guys, new here and hope this section will be ok to post my problem as I am not entirely sure what it falls under. I am re-designing my website and changing it to php. Everything has gone well, the only thing I have used php for is uncluded and forms to email.

Now it's a hard problem to explain but will try my best. It seems as though I have got confused along the way with my file structure. Working on a test server (from my own computer) it works fine but when I uploaded my files to my host I ran into problems.

The files in my root directory display the webpages correctly but any files in a sub folder such as /portfolio do not display correctly. What happens is the images in the sub folder do not work (images for the main site, i.e the layout).

I have a folder called includes, my root looks like this:
[i104.photobucket.com ]

In the includes folder I have three files, header.php right-section.php and footer.php

For this example let's focus on header.php
In header.php I have the top part of my design, including images for the layout. The filepath for the images is like this: /images/example-image.jpg

Now the root files understand this and when the include is called it displays all the images correctly however if a page from a sub folder, for example a page at this level: /portfolio/client-name.php

This page will load and have the includes working but any images in the header.php will not load. I have tested this and if I add this: ../images/example-image.jpg to the code in my header.php file then it makes the images show for the sub folders but then the images do not show for any webpages in my root folder...does this make sense?

I am hoping there is an easy solution that I can understand, I am not good with php and there must be a way to do it as my site is not even that big compared to some of the websites on the internet. There must be a way to keep organised without duplicate files.

Apologies for how long this message is and appreciate any help.

Thanks
Kev

rocknbil

9:08 pm on Aug 23, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome aboard liltman,

The filepath for the images is like this: /images/example-image.jpg


That should work, seriously, is your domain an alias or something? Drop a phpinfo.php in your images directory, see what it says for SCRIPTNAME. In particular look where $_SERVER['DOCUMENT_ROOT'] is pointing to.

$_SERVER['DOCUMENT_ROOT'] normally points to *something* like this

/var/www/example.com

But I'm suspecting you have an alias, let's say a directory that has been assigned a domain. So if example2.com is pointed at "second_domain,"

/var/www/example.com/second_domain

You may need to do

/second_domain/images/example-image.jpg

Doesn't make a lot of sense, and is certainly not expected behavior.

liltman

10:10 pm on Aug 23, 2010 (gmt 0)

10+ Year Member



Hey, will try your suggestion shortly but just want to quickly comment on the domain thing. Not sure what an alias is but currently the test server I am using has no domain name, I am accessing it directly from the ip address...I currently have a website but do not want to overwrite or confuse myself by testing on the same space as the live website. If it's a likely problem due to the ip and you think it will work when I upload it to my host with a domain then I guess I have nothing to worry about!

I am clueless when it comes to the really technical side of things lol, not sure if that helps you or not, will see if I can do the things you have suggested, what is a phpinfo.php though, what do I put inside the php file? - that's how little I know about php lol

Thanks for the help so far.

liltman

2:47 am on Aug 24, 2010 (gmt 0)

10+ Year Member



Hey, just an update, I tried it on my host with a domain and it seems to work perfectly! I thought something was wrong as the way I structured it should of worked :)

Not sure why it didn't when it went by IP address instead of domain name but anyways now I know it works.

Thanks for the help rocknbil

rocknbil

4:21 pm on Aug 24, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a **possible** explanation (may be incorrect.)

If your hosting service has a fixed IP, like a dedicated server or VPS, you probably only have one IP bound to the server or VPS. Since there's no domain name, when you request it by IP it's probably trying to access the "virtual_hosts" directory in the below fictional scenario:

/var/www/virtual_hosts/example.com
/var/www/virtual_hosts/example-two.com
/var/www/virtual_hosts/example-three.com

Or, likely the server/vps has a way of managing direct IP requests, wherever it points to it's not where your files are. :-)

liltman

7:20 pm on Aug 24, 2010 (gmt 0)

10+ Year Member



Thanks! it's reseller hosting accoutn so you might be right! either way it should work when I get the site online, I have now got a free domain set up for future testing and it worked ok!

So either way we have found a solution together even though the php stuff confused me haha.

Thanks a bunch!