Now a days I am designing a website in php and I want to add more than 5 pages which should have same styles for ex- All the pages should have same header, footer, left side bar, right sidebar etc.
I know that I can do this using include() method but I am unable to use it effectively.
I have created some pages like below.
header.php-
<html><body><div><img src="logo.png"/></div></body></html>
leftsidebar.php
<html><body><div>Categories<ul><li>business</li><li>management</li><ul>div></body></html>
index.php- this is the main file where I wan to include files.
<html>
<body>
<div class="top">
<?php include("header.php"):
?>
</div>
<div class ="leftsidebar">
<?php include("leftsidebar.php"):
?>
</div>
</body>
</html>
the problem is that layout is not proper. I dont know where I have to use width and height style proprties for div whether I should use div width in index.php or header.php. And one problem is when I view the source code I can see some duplicate elements like html,head,body etc.
I would appreciate if somebody know how to use this effectively.
Looking forward to your answers.
First point:
you are including php files that contain html and body tags that are also present in the page where you are including them... keep them only in the initial page where you put the includables.
header.php
should be:
<div><img src="logo.png"/></div>
leftsidebar.php
should be:
<div>Categories<ul><li>business</li><li>management</li></ul></div>
Second point:
to have styles across the different pages you should use css external stylesheets and not inline styles. Have a look here