Search code examples
phphtmlpathwampabsolute

what is the difference of absolute path in html and php?


I am developing a website on php, I have installed wamp on my personal computer and my website files are in the www folder of wamp. now considering www as my root folder i have a template folder in the root folder and header.inc.html file in the template folder. when I try to include this header.inc.html file in any other php file using an absolute path include('/template/header.inc.html'); it gives me error "Failed to open stream: No such file or directory", but when I create a simple html link using the same absolute path it works perfectly and opens the file. below is my test code

<?php
echo '<a href="/template/header.inc.html">headerfile</a>';
include('/template/header.inc.html');
?>

if I give the full path for example C:/wamp/www/template/header.inc.html to the include function it works fine.

I am confused that this problem is occurring on my wamp server only and it would work perfectly on any webhost server, or maybe the same problem will exist on a webhost

I would appreciate any help that would clarify my confusion, Thanks.


Solution

  • Absolute paths on the server start from the server's hard disk (C:\).
    Absolute paths on the client start from the root of the website (http://example.com/).