Page 1 of 1
A simple include problem
Posted: Sun May 25, 2003 6:04 am
by Aqua
Hi, I'm a relative newbie in PHP. I've been using PHP for some time now just for the include function. This time however, I can't seem to get it to work, even after exhausting all (I think) trials to find what's wrong. Here's the problem.
In index.php, I have the following:
Code: Select all
<BODY <?php include "PHP/PHP_Body_Tag.php" ; ?> >
PHP/PHP_Body_Tag.php:
Code: Select all
<?
echo "BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#B9B9B9"
ALINK="#B9B9B9" VLINK="#B9B9B9"" ;
?>
The path of the include statement is correct as both /PHP and index.php are located in root.
I know this is very basic but I really need your help please (I'm stuck!). Can you please tell me what I'm doing wrong here? Thank you!
Posted: Sun May 25, 2003 6:20 am
by volka
if you could tell us what should happen and what does happen?
If you open your browser's source view do you see the code of PHP_Body_Tag.php instead of the result?
Posted: Sun May 25, 2003 6:25 am
by evilcoder
Your error would be a parse error because you haven't escaped your double quotes inside your echo.
Try this:
Code: Select all
<?php
echo "BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#B9B9B9"
ALINK="#B9B9B9" VLINK="#B9B9B9" " ;
?>
Posted: Sun May 25, 2003 6:40 am
by Aqua
Sorry, forgot to mention that loading the page produces a half empty page where there is nothing on top. When I view the source code, I cannot see the php output.
evilcoder: I tried escaping the double quotes but the problem is still the same.
Posted: Sun May 25, 2003 6:45 am
by evilcoder
ok give this a try:
Put this at the top of the page your including into:
Code: Select all
<?php
$bodyvars = include( "filewithechoinit.php" );
?>
<body <?=$bodyvars ?> >
Posted: Sun May 25, 2003 6:49 am
by volka
first of all, you let the script write the contents
into the tag. At least it must be
Code: Select all
<BODY><?php include "PHP/PHP_Body_Tag.php" ; ?></BODY>
if you change it to
Code: Select all
<BODY><?php error_reporting(E_ALL); ini_set('display_errors', TRUE); include("include.php"); ?></BODY>
does it display any errors?
edit: oops, you want to write properties. forget about the <body></body> but do enable error_reporting/displaying

Posted: Sun May 25, 2003 7:12 am
by Aqua
evilcoder: I tried that and now I get the contents of the include file echoed on the page instead of it being used for the <body> properties.
volka: I tried your suggestion, I get the contents of the php include file on the page with no errors.
I know the problem is so tiny and that is why I can't seem to find it, atleast I hope.
Posted: Sun May 25, 2003 7:18 am
by werlop
Mabye im missing something here, but if all he wants to include is what he has here:
Code: Select all
<?
echo "BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#B9B9B9"
ALINK="#B9B9B9" VLINK="#B9B9B9"
?>
Then why does he need php at all for the include file?
Couldn't the file to be included just be:
Code: Select all
"BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#B9B9B9"
ALINK="#B9B9B9" VLINK="#B9B9B9"" ;
Then just do <body <?php include( "filetoinclude.php" ); ?>></body>
Sorry if I'm missing something
David
Posted: Sun May 25, 2003 7:31 am
by volka
not at all, werlop. It can also be handled via css without any php-support.
But it should work either way

I've tried the code
Code: Select all
<?php // PHP_Body_Tag.php
echo "BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#B9B9B9" ALINK="#B9B9B9" VLINK="#B9B9B9" " ;
?>
Code: Select all
<?php // test.php
<BODY <?php include "PHP/PHP_Body_Tag.php" ; ?> >
test
</BODY>
and the output was (as expected)
Code: Select all
<body BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#B9B9B9" ALINK="#B9B9B9" VLINK="#B9B9B9" >
test
</body>
can you describe the problem again (expectiations, visible results, generated output), Aqua?
Posted: Sun May 25, 2003 7:45 am
by Aqua
volka: It's like you said, trying to substitute PHP for CSS. I would like the body tag to acquire its attributes from the included PHP/PHP_Body_Tag.php file. When I load the page (index.php which includes the include function), I don't see the top part of the page. After I started following your suggestions along with evilcoder's, I started getting the output displayed on the page instead of it being used as an attribute for the <body> tag. To explain further, I want to see the contents of the include file in the page's html source code and not on the page itself (
http://www.dzp.com/Web). Do I make sense hehe?
Posted: Sun May 25, 2003 7:55 am
by Aqua
Just to add (sorry I just remembered), all my php include coomands on the same page are not working as their output is not visible on the page's source code. Thanks again!
Posted: Sun May 25, 2003 9:14 am
by volka
ok, I think it's time for a little rollback before you destroy your script ceompletely because of our
help
After I started following your suggestions along with evilcoder's, I started getting the output displayed on the page instead of it being used as an attribute for the <body> tag.
that's right.mark my
edit: oops, you want to write properties. forget about the <body></body> but do enable error_reporting/displaying
so my suggestion was
Code: Select all
<BODY <?php error_reporting(E_ALL); ini_set('display_errors', TRUE); include("include.php"); ?> >
to enable the error output. since it would happen withing the body-tag the rendered result (note the difference between script-output and rendered result within the client/browser) might be broken and you had to open the browser's source view (where you can see the script's output).
now for evilcoder's suggestion
evilcoder wrote:<?php
$bodyvars = include( "filewithechoinit.php" );
?>
<body <?=$bodyvars ?> >
it includes
and executes filewithechoinit.php, so anything that is echoed in
filewithechoinit.php will be added to the output stream. $bodyvars would fetch a global scope return value of
filewithechoinit.php, but there isn't any. So the output of
filewithechoinit.php (
PHP/PHP_Body_Tag.php in your case) will take place before the <body>-tag and <?=$bodyvars ?> might be executed (
if short-tags are enabled) but print nothing (in the worst case it would print
1, which you might check in the browser's source view)
css seperates the layout from the contents, e.g. try
Code: Select all
<html>
<head>
<style type="text/css">
body { background-color: white; color: black; }
p { background-color: silver; }
p.redbg { background-color: red; }
a { color: #B9B9B9 }
a:hover { color: green }
</style>
</head>
<body>
<a name="anchor1" ></a>
<p>bla bla bla</p>
<a name="anchor2" ></a>
<p class="redbg">bla bla bla</p>
<a href="#anchor1">goto anchor #1</a>
<a href="#anchor2">goto anchor #2</a>
<a href="javascript:void()">do nothing</a>
</body>
</html>
but the stylesettings are still within the page. You can write them to a different file and let the browser include it.
stylesA.css:
Code: Select all
body { background-color: white; color: black; }
p { background-color: silver; }
p.redbg { background-color: red; }
a { color: #B9B9B9 }
a:hover { color: green }
index.html:
Code: Select all
<html>
<head>
<link rel="stylesheet" type="text/css" href="stylesA.css">
</head>
<body>
<a name="anchor1" ></a>
<p>bla bla bla</p>
<a name="anchor2" ></a>
<p class="redbg">bla bla bla</p>
<a href="#anchor1">goto anchor #1</a>
<a href="#anchor2">goto anchor #2</a>
<a href="javascript:void()">do nothing</a>
</body>
</html>
if you define different stlyes in different files all your php script has to do is to write the url to the href-property of the link-element
Code: Select all
<?php $urlCSS = 'stylesA.cc'; // or somthing more complex ?><html>
<head>
<link rel="stylesheet" type="text/css" href="<?php echo $urlCSS; ?>">
</head>
<body>
<a name="anchor1" ></a>
<p>bla bla bla</p>
<a name="anchor2" ></a>
<p class="redbg">bla bla bla</p>
<a href="#anchor1">goto anchor #1</a>
<a href="#anchor2">goto anchor #2</a>
<a href="javascript:void()">do nothing</a>
</body>
</html>
Posted: Sun May 25, 2003 9:01 pm
by Aqua
Sorry for the delayed reply, I was away at work. Anyway, I decided to start over and replaced the above problem-causing script with CSS (although I still prefer it to be PHP). Everything is working fine now. Thank you everyone for your kind help.