First off I googled a million pages and just could not find answers .
I am trying to do this:
In a configuration.php file I want to set up the path to my site
I currently have this
<?php
$siteroot = $_SERVER['DOCUMENT_ROOT'];
?>
In my other files I want to simply create blank containers and just include pages. So for instance in Index.php I want to include header.php, sidebar.php and footer.php.
I currently have this:
At the top of my page I am calling the configuration.php: <?php require_once (“includes/configuration.php”);?>
And in the spot where I want my header to appear I use this:
And likewise for all the other includes - sidebar.php and footer.php.
This does not work, I get this error message:
[b]Warning[/b]: include(D:/wamp/www//includes/module-header.php) [[function.include](http://localhost/imi/function.include)]: failed to open stream: No such file or directory in [b]D:\\wamp\\www\\imi\\index.php[/b] on line [b]105[/b]
Now I want this to work in my local server and seamlessly work in production.
I have no understanding and what code I am using was from one of my many google adventures… it apparently is incorrect.
That works - so when I take this to production, should the base directory change to http://www.sitename.com/" or the server path? If either one will work which is recommended?
Defining the base URL is still recommended, particularly when you start scaling out to multiple servers or use a CDN. If you have no plans to do that, then sure, you could simply use the relative href.
this looks like what i’ve been looking at in this thread. i would need to include that configuration.php in every php file no matter what folder it is? that would be using relative paths i imagine… just getting utterly confused trying to solve a pretty similar problem…
For html you just use /
<a href=“/some/directory/img.php”> <– that url is the absolute path from the web servers root
<a href=“img.php”> <– that url is relative to what directory you are currently in
For php paths, you are no longer talking about the web server root, but the servers file system. So you need $root to be the path to your project, eg /home/hash/websites/myproject/
You can set this based off the DOCUMENT_ROOT, or based on an entry point in your script, or other ways, like hard coding a config file.