inserting html using php not working...

User 355448 Photo


Ambassador
3,144 posts

I know enough about php to know I don't know very much.

I have been using php to insert parts of my pages that are consistent from page to page, such as the footer, and masthead,using code such as this:
<?php include($DOCUMENT_ROOT . "/x_includes/disclaim.php"); ?>

While looking for what an error page (401, 403, 404, etc.) should look like, I found a page that among other things has some php above the doctype and below the </html> tag, that works with some code in the middle of the page to hide an email address. I know I can remove this code, and I likely will remove it, but I want to know why it kills my php inserts. The page that is currently messed up is http://www.brighterdaycharities.org/err/401.php which only has one insert near the bottom of the page.

When you view the source at the page, you do not see the php at the top and bottom, so here it is:

<?php //Ûž//text{encoding:utf-8;bom:no;linebreaks:unix;text:4 spaces/tab;}// initialize..
do_init();
include ('mail-mash.php');
$email_addy = mail_mash('webmaster@roberson-family.com');echo '<?xml version="1.0" encoding="utf-8"?>

that was at the very top of the page, and here is what is at the very bottom of the page:
';
// init
function do_init() {
global $corz_root, $doc_content;
if (stristr(@$_SERVER['HTTP_ACCEPT'],'application/xhtml+xml')) {
$doc_content = 'application/xhtml+xml';
} else {
// read: "Internet Explorer"
$doc_content = 'text/html';
}
$corz_root = $_SERVER['DOCUMENT_ROOT'];
}
?>

I suppose this will be very simple after someone explains it to this old man. :)
User 37670 Photo


Registered User
2,138 posts

Hi Bill,

Notice, in your piece of php code, you open and close the php tags:
<?php include($DOCUMENT_ROOT . "/x_includes/disclaim.php"); ?>
In the code you gave us, the php tag is opened at the top of the page <?php but not closed until the very bottom of the page 'DOCUMENT_ROOT'];
}
?>

So, when you added your piece of the code, you re-opened the php tag without closing it, then you close it essentially twice on the same page. That could be the cause.
Maybe close the php tag, insert your code, then open it again and see if that fixes it, or just put your code in without the open and close tags. Those are just guesses and things I'd try.

Good Luck
E-Learning Specialist
www.mainsites.ca is my website, and yes, some of it is crappy.

Have something to add? We’d love to hear it!
You must have an account to participate. Please Sign In Here, then join the conversation.