Solved

Reading in file in PHP

Posted on 2001-08-08
7
215 Views
Last Modified: 2008-03-06
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?
0
Comment
Question by:system
7 Comments
 
LVL 1

Expert Comment

by:bowker
ID: 6366135
Hi --

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.inc.php");
     }
?>

<!-- rest of HTML for the page -->

</BODY>
</HTML>
0
 
LVL 1

Expert Comment

by:bowker
ID: 6366149
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.indexOf("Mac") != -1);
    var IE4M = HM_IE4 && HM_Mac;
// -->
</script>

</head>

<body bgcolor="white" background="graphics/bg1.gif" text="black">

0
 
LVL 5

Accepted Solution

by:
harwantgrewal earned 200 total points
ID: 6366950
What I think you should make a header file with the naming convention like inc_header.php write what every you want to write in that file e.g

<html>
<head>
<title>
Here title goes
</title>
</head>
<body marginheight="0" vlink="red">


and include your header file in all the file in the first line

<?
include ("inc_header.php");
?>
If you change anything in the header file it will reflect in all the file where you had include the file.

Harry
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Expert Comment

by:curri
ID: 6367525
It seems what you want is templates. Have you looked into the FastTemplate library ?
0
 

Author Comment

by:system
ID: 6369948
Thanks Harry,

that solution was very straightforward...
Thanks to everyone else who posted.
0
 

Author Comment

by:system
ID: 6370012
Thanks harry,

good answer. Thanks to everyone who posted even more elaborate answers. Harry's is the simplest and easiest to implement.
0
 
LVL 1

Expert Comment

by:bowker
ID: 6370484
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.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now