0

I have an issue with finding paths with includes in my site. I use the method i know but coud not get it right: Here is how my site is composed

1- Main foldername is:kbaboutik: Inside we have:

images
css
includes
index.php

subfoldername:Man-clothes
index.php

So, the issue have is that I have tried to include header.html.php from the includes folder into man-clothes index.php with this method:

<?php
$pathroute = $_SERVER['DOCUMENT_ROOT'];

include_once $pathroute."kbaboutik/includes/header.html.php";
 ?>

But it does not work the way expected; the html element of the header.html.php apppears unstyled and the images also do not not appear.

Can somebody help me out?

Thanks

Doss Smart
  • 77
  • 1
  • 1
  • 7
  • Try `include_once $pathroute."/kbaboutik/includes/header.html.php";`, i.e. add a slash. – lxg Oct 10 '15 at 21:44
  • @lxg i did, but same situation; the text appear unstyled and the images also are missing – Doss Smart Oct 10 '15 at 21:49
  • 2
    if relatives, the path to css, images, etc are relatives to the "container" (index.php) and not to the files where they are referenced (e.g. /includes/otherfiel.php ) – Julio Soares Oct 10 '15 at 21:50
  • @DossSmart: Ok, sorry ... I misread the last part of your question. – lxg Oct 10 '15 at 21:54
  • Possible duplicate of [PHP include relative path](http://stackoverflow.com/questions/17407664/php-include-relative-path) – Ragdata Oct 10 '15 at 23:07
  • @Ragdata; There is no duplicate of PHP include relative path; it is not the same issue..I have even tried the techniques mentioned there..but still stuck..So i really need help.. – Doss Smart Oct 11 '15 at 09:56
  • @DossSmart can you please add some code, of what you have, what is showing, and what was supposed to show? – mloureiro Oct 11 '15 at 10:47

1 Answers1

0

Check the path in your header.html.php. Images and stylesheets should look like this:

   <img src="/images/model1.jpg">

Starting with a "/" and then a path relative to your document root.

Viktoras
  • 53
  • 8
  • i am afraid i do not get very well what you mention..could you please mention an example? – Doss Smart Oct 10 '15 at 22:03
  • So, PHP is a server side language. What it does in your case - renders the HTML. As you say, the header contents does really get included to the page, this means PHP has done everything right. But the images are missing. So I think that the problem is in the header.html.php. The browser opens the page, and in the HTML there are links where the stylesheets and images are located. At this point it doesn't matter where the HTML came from, header or index page, it the single page now. So you need to specify the path to the image relative to the web site root. Like I've written: src="/images/1.jpg" – Viktoras Oct 10 '15 at 22:12