system
asked on
Reading in file in PHP
I would like to be able to make a header,
which all my PHP modules can read in..
That way if I ever change the header, I only have
to change it on one page.
I assume that the easiest way is to make a
text file with the HTML of the header and to read
in and insert that text file on all pages?
which all my PHP modules can read in..
That way if I ever change the header, I only have
to change it on one page.
I assume that the easiest way is to make a
text file with the HTML of the header and to read
in and insert that text file on all pages?
Sorry, I left out the contents of header.inc.php ...
<?PHP
// put any PHP stuff here - maybe read in BODY variables from a DB table
?>
<SCRIPT language="JavaScript">
<!--
var DOM = (document.getElementById) ? true : false;
var NS4 = (document.layers) ? true : false;
var IE = (document.all) ? true : false;
var IE4 = HM_IE && !HM_DOM;
var Mac = (navigator.appVersion.inde xOf("Mac") != -1);
var IE4M = HM_IE4 && HM_Mac;
// -->
</script>
</head>
<body bgcolor="white" background="graphics/bg1.g if" text="black">
<?PHP
// put any PHP stuff here - maybe read in BODY variables from a DB table
?>
<SCRIPT language="JavaScript">
<!--
var DOM = (document.getElementById) ? true : false;
var NS4 = (document.layers) ? true : false;
var IE = (document.all) ? true : false;
var IE4 = HM_IE && !HM_DOM;
var Mac = (navigator.appVersion.inde
var IE4M = HM_IE4 && HM_Mac;
// -->
</script>
</head>
<body bgcolor="white" background="graphics/bg1.g
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
It seems what you want is templates. Have you looked into the FastTemplate library ?
ASKER
Thanks Harry,
that solution was very straightforward...
Thanks to everyone else who posted.
that solution was very straightforward...
Thanks to everyone else who posted.
ASKER
Thanks harry,
good answer. Thanks to everyone who posted even more elaborate answers. Harry's is the simplest and easiest to implement.
good answer. Thanks to everyone who posted even more elaborate answers. Harry's is the simplest and easiest to implement.
system --
Harry's answer indeed is the simplest, but it's the least flexible, and it's dangerous - if you include your entire <HEAD> ... </HEAD> within the include file, the spiders and robots will only find that one include file and nothing else. If you want to be listed by any of these search engines, you'll have to put all the <META> tags in every script ...
Which means that you may not want to include the file in every script ...
But if you don't need to be listed, and you want the SAME include in every script, then Harry's is the best answer.
Good luck!
Bob.
Harry's answer indeed is the simplest, but it's the least flexible, and it's dangerous - if you include your entire <HEAD> ... </HEAD> within the include file, the spiders and robots will only find that one include file and nothing else. If you want to be listed by any of these search engines, you'll have to put all the <META> tags in every script ...
Which means that you may not want to include the file in every script ...
But if you don't need to be listed, and you want the SAME include in every script, then Harry's is the best answer.
Good luck!
Bob.
Do it as an include() or require_once() ... and name the file to be included something.inc.php - this plugs a security hole in PHP. Also, be aware that if you put META tags in the include file, you're reducing the chance for spiders and robots to log your pages for listings ...
<?PHP
$loadHeaderForThisPage = 1;
?>
<HTML>
<HEAD>
<TITLE></TITLE>
<META ........>
<META ........>
<META ........>
<?
if ($loadHeaderForThisPage) {
include("includes/header.i
}
?>
<!-- rest of HTML for the page -->
</BODY>
</HTML>