Reputation: 1571
Hi I am trying to crate a website using php, and the structure looks like the following:
-index.php
-header.php
-footer.php
-style.css
-images\{images are in this folder}
-\web\index.php
-\contact\index.php
The thing is i am using php's include function on all the index.php files to use the header.php and footer.php files, but the problem is that only the index.php in the root folder is showing the styles, but when i open localhost/web/index.php the page looks broke as the css and images are not found.
How can i resolve this problem.
Help please
Upvotes: 1
Views: 147
Reputation: 3518
add site name in a verible like
$site_base_url = "http://localhost/web";
after that add it in front of url when u using php like
echo '<link type="text/css" href="'.$site_base_url.'/style.css" rel="stylesheet" charset="utf-8">'
or like
echo '<img src="'.$site_base_url.'/images/file_name.jpg" />'
when you use functions use global
like this
function find_user(){
global $site_base_url;
echo "no users found";
echo '<a href="$site_base_url">return home</a>
}
Upvotes: 1
Reputation: 157915
very easy.
you have to start every path from the site root, which is simply /
.
so, addressing style.css as a /style.css
will let it be called from any page of the site.
same goes for all the local hyperlinks on the site - just start them from the /
(followed by the correct path of course)
Upvotes: 0
Reputation: 917
in your style.css you can use
background-image:url(/images/mycoolpic.png);
Upvotes: 0