ClioSport.net

Register a free account today to become a member!
Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

  • When you purchase through links on our site, we may earn an affiliate commission. Read more here.

PHP includes. Help



  306 TD Slut
Am i doing this right? i preview it locally on my machine and it doesnt show the header.php at the top but if i upload it to my space online it does..

heres the index.php code:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd[/URL]">
<html xmlns="[URL]http://www.w3.org/1999/xhtml[/URL]">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHP Include Test</title>
<style type="text/css">
<!--
body {
 margin-top: 0px;
 margin-right: auto;
 margin-bottom: 0px;
 margin-left: auto;
 font-size: 0.8em;
 color: #999999;
 text-align: center;
}
#header {
 width: 700px;
 position: relative;
 height: 80px;
}
#content {
 background-color: #CCCCCC;
 width: 700px;
 position: relative;
 height: 500px;
}
#wrapper {
 margin-top: 0px;
 margin-right: auto;
 margin-bottom: 0px;
 margin-left: auto;
 height: auto;
 width: 700px;
 position: relative;
}
#footer {
 width: 700px;
 position: relative;
 height: 80px;
}
-->
</style>
</head>
<body>
<div id="wrapper">
<?php include("header.php"); ?>
<div id="content"></div>
<div id="footer"></div>
</div>
</body>
</html>

(i know the css is in the document and not linked in, just playing about and couldnt be arsed to do it properly)

here is the header code:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd[/URL]">
<html xmlns="[URL]http://www.w3.org/1999/xhtml[/URL]">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>
</title>
<style type="text/css">
<!--
p {
 font-size: 0.8ems;
 color: #CCCCCC;
 font-family: Verdana, Arial, Helvetica, sans-serif;
}
#header {
 background-color: #993333;
 height: 80px;
 width: 700px;
 position: relative;
}
-->
</style>
</head>
<body>
<div id="header">
<p>welcome to php include test blah blah blah blah blah</p>
</div>
</body>
</html>


both files are saved as .php too.

am i missing something out?

thanks
 

KDF

  Audi TT Stronic
No your putting too much in the include file.. you are declaring <head> <body> etc. twice !

Put the CSS in the header.php into the main php file, get rid of everything in the header.php file except for

Code:
<div id="header">
<p>welcome to php include test blah blah blah blah blah</p>
</div>

even delete the </body> and </html> after the div tag closes.. you dont need to declare stuff twice !
 

KDF

  Audi TT Stronic
infact the div tags should go in the main file too lol.. your over complicating things that don't need to be !

just the <p>welcome to php include test blah blah blah blah blah</p> should go in the header.php file..

like so

main file (now includes css from header and <div> tags from header)
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHP Include Test</title>
<style type="text/css">
<!--
p {
 font-size: 0.8ems;
 color: #CCCCCC;
 font-family: Verdana, Arial, Helvetica, sans-serif;
}
#header {
 background-color: #993333;
 height: 80px;
 width: 700px;
 position: relative;
}
body {
 margin-top: 0px;
 margin-right: auto;
 margin-bottom: 0px;
 margin-left: auto;
 font-size: 0.8em;
 color: #999999;
 text-align: center;
}
#header {
 width: 700px;
 position: relative;
 height: 80px;
}
#content {
 background-color: #CCCCCC;
 width: 700px;
 position: relative;
 height: 500px;
}
#wrapper {
 margin-top: 0px;
 margin-right: auto;
 margin-bottom: 0px;
 margin-left: auto;
 height: auto;
 width: 700px;
 position: relative;
}
#footer {
 width: 700px;
 position: relative;
 height: 80px;
}
-->
</style>
</head>
<body>
<div id="wrapper">
<div id="header"><?php include("header.php"); ?></div>
<div id="content"></div>
<div id="footer"></div>
</div>
</body>
</html>

header.php
Code:
<p>welcome to php include test blah blah blah blah blah</p>
 
  Rav4
The way I do it is split it into 3.

header.php
index.php
footer.php



Header would include the CSS file.

index.php would obviously be replaced by each page.........

The easiest way I find is to create one page, then say, ok this top bit is going to ALWAYS* be the same, that will be the header, this middle but is going to change, that can be the bits that change, this last bit is going to be the same all the time, so that can be the footer......

:)

There we are :)
 
  306 TD Slut
cheers mushty i'll give it another go tomorrow, i still cant get it to preview properly without uploading to the net.
 
  1.2 16v Dynamique
Wow this is some crazy shizzle, i know comps quite well but this is waaaay beyond me...GL guys!
 
  Now Clio-less... Derv :/
cheers mushty i'll give it another go tomorrow, i still cant get it to preview properly without uploading to the net.


deffo won't be a problem with your content mate.. doesn't matter if you repeat doctype and html tages, it should still show.

If it doesnt work locally but does online, it might suggest a problem with your PHP server.. perhaps it is configured to turn includes off?

To check.. go to the very basics.. don't confuse yourself with miles of code.

Start with 2 files - index.php and include.php

index.php should just contain something like:

PHP:
This is a PHP test:<br />

<?php

echo "Hello World<br /><br />";

?>

This is a PHP Include test:<br />

<?php

include("include.php");

?>
include.php:

PHP:
This is the the include.php file!
index.php will test that PHP is actually working properly first by outputting "Hello World" - if that doesnt show, you have a problem with PHP. If it does show, but your include.php text does not, you have a problem with includes in your PHP config.

If this is the case, check http://uk.php.net/manual/en/function.include.php for info on the include(); function

Remember: PHP.net will help you out no end when learning to code.

Hope this helps
Roggo
 

KDF

  Audi TT Stronic
It very much does matter if you redeclare html tags more than once.. especially if viewed in a browser that follows proper standards !

Do it right first time and save a headache later on !
 
  Now Clio-less... Derv :/
i dont really think that strict standards are his priority at the minute tbh mate.. and anyway, regardless of whether he repeated the tags or not, the include should still have worked.. that was the point i was making.

yes it is important to comply with web standards, but i think it's more important that you understand what you're doing first rather than over complicating things.
 

TeZ

  Non RS : (
It very much does matter if you redeclare html tags more than once.. especially if viewed in a browser that follows proper standards !

Do it right first time and save a headache later on !

SO TRUE.
 

KDF

  Audi TT Stronic
yes it is important to comply with web standards, but i think it's more important that you understand what you're doing first rather than over complicating things.

And thats why I was teaching him to use HTML properly first before tackling PHP.


1 step at a time eh.
 


Top