PHP Include, file help!

stillDOLL

New Member
Messages
11
Reaction score
0
Points
0
I'm new to PHP but I just mangaged to put the content which I am going to use on all my pages on a "header.php" file and the other content which I put on a "footer.php" file. And the tutorial I was reading says to type in the script like this:

<?php include('header.php'); ?>
<div style="position: absolute; left: 246; top: 619; width: 574; height:180">
<div style="width: 574; height: 224"><p class="Header">Welcome~</div>
</div>
<?php include('footer.php'); ?>

I've done that and I even uploaded the "header" and the "footer" onto my server but when I upload this as one PHP file (main.php) and preview it it's just a blank screen with "Welcome~" on it!! >w<

Can someone please tell me what I'm doing wrong? and if I'm not doing this wrong does x10 support PHP??


Thanks!~^^,

Ann

-btw, if you don't get what I'm saying please feel free to email me at vampireheart.stilldoll@hotmail.com
 

freecrm

New Member
Messages
629
Reaction score
0
Points
0
Couple of things to watch out for here...

Firstly, all my includes have double quotation marks (") but I'm not sure that has any relevance.

More importantly is the location of the included file. If they are in the same directory as the file you are including them into - there shouldn't be a problem but if they are in a directory above/below/different - you need to specify the path correctly.

Lastly (and this is probably the reason), your included file can only be the body part of a page. In other words, you need to strip out everything above (and including) <body>

Very simply put, your included files should only have code like this...

PHP:
<table>
<tr>
<td>Welcome</td>
</tr>
</table>
<?php echo $_SESSION['username']; ?>

If headers, opening or closing tags are in the include file, it confuses the page you are including them in.

Your main page would look something like this.

PHP:
<html>
<head>
<title>Title</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php include("header.php"); ?>
<div style="position: absolute; left: 246; top: 619; width: 574; height:180">
<div style="width: 574; height: 224"><p class="Header">Welcome~</div>
</div>
<?php include("footer.php"); ?>
</body>
</html>

Yes, X10 does support php!
 

Scoochi2

New Member
Messages
185
Reaction score
0
Points
0
<?php include('header.php'); ?>
<div style="position: absolute; left: 246; top: 619; width: 574; height:180">
<div style="width: 574; height: 224"><p class="Header">Welcome~</div>
</div>
<?php include('footer.php'); ?>

I've done that and I even uploaded the "header" and the "footer" onto my server but when I upload this as one PHP file (main.php) and preview it it's just a blank screen with "Welcome~" on it!! >w<
Hmm. I would ask if the header and footer are named exactly that, not header.php.html or anything, and that they are in the same directory as the file that includes them.
But if that was the case, PHP would give an error.

Because you get no errors, I can only assume that your header and footer are either blank, or have no output in them. For example, the following example header.php will output nothing and would look exactly like what you're getting above.
PHP:
<?php
$a = 10;
$b = 3;
$c = $a + $b;
?>
<!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" dir="ltr" lang="en">
<head>
<title>Index page</title></head><body>

One other thing to check, the file that is trying to include is a PHP file, right? But again, it would output the PHP code if it was HTML...
index.php?


Have you viewed the source of your file? Because if you look at my example above, it will show nothing on the page. But it will output the headers in the source...
 
Last edited:

sycoblast

New Member
Messages
4
Reaction score
0
Points
0
<?php include('header.php'); ?>
<div style="position: absolute; left: 246; top: 619; width: 574; height:180">
<div style="width: 574; height: 224"><p class="Header">Welcome~</div>
</div>
<?php include('footer.php'); ?>


--------

Instead of "including"

why not just "echo" your header/footer ... or if your page is scripted in HTML just have it in "class" text so you can avoid using headers and footers... It also slows down the page when you have excessive .php scripts for no reason... Like this.
 

freecrm

New Member
Messages
629
Reaction score
0
Points
0
why not just "echo" your header/footer ...

Interesting point.. what's the syntax for this and why do we even have an include function?

If you echo a page, does it process any included php?

What are the pro's con's?
 

exemption

New Member
Messages
66
Reaction score
0
Points
0
Why use HTML inside of PHP when you can simply use PHP through out?

such as this

PHP:
<?php
include "header.php";
include "w/e.php";
include "file.html";
?>
'
something like that is super simple
 

xav0989

Community Public Relation
Community Support
Messages
4,467
Reaction score
95
Points
0
What I do is I create a header and footer template in html, and I have a function that reads them and echos them. This is, in my opinion, the simplest way.
 

stillDOLL

New Member
Messages
11
Reaction score
0
Points
0
Hey!!^^ Thanks everyone who replied!!!^^ I've got the problem fixed now XD
So thank you very very much!!!!^^
 

dickey

New Member
Messages
128
Reaction score
0
Points
0
Then I guess you have to close this thread. post one more time and tick the close thread option. before posting.
 
Top