Welcome to WebmasterWorld Guest from 54.161.228.30

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

PHP +same content on all pages of a site

same content on all pages of a site

   
6:23 pm on Dec 20, 2002 (gmt 0)

10+ Year Member



I need to include the same content on every page of my website. However, sometimes it changes. I want to be able to change it only once, instead of having to change the same item on every page. I've looked into both PERL (scary!) and php, but I'm not sure where to begin. I know that it has something to do with Server Side Includes, but that's about it...Does anyone have any suggestions?
7:21 pm on Dec 20, 2002 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Welcome to WebmasterWorld [webmasterworld.com] princess

You can use the php include function [php.net]

it would look something like this if you wanted to include a file in the same dir as the page calling it.

<?
include "somefile.html";
?>

7:46 pm on Dec 20, 2002 (gmt 0)

10+ Year Member



So I put this into all my pages where I want the information to be, then make a seperate html file with the information? Do I set up the new file with header and body tags?
7:50 pm on Dec 20, 2002 (gmt 0)

WebmasterWorld Senior Member littleman is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Princess, just curious -- why not just use ssi?
7:52 pm on Dec 20, 2002 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



you need php parsing for the file extension where you are placing the include statement.

You then place the include code in there making sure the path to the included file is correct no matter where on the site the page including it is located.

You could use
include $DOCUMENT_ROOT . "/somefile.html";
OR
include $DOCUMENT_ROOT . "/includedir/somefile.html";

makes the path absolute so that it won't break.

new file with header and body tags

nope, php will take the content in the included file and put it into the other page as is. Only put the code to be included in there. You don't need anything extra. Look at the source through a browser once the include is in there and you will see more what I mean.

7:54 pm on Dec 20, 2002 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



a very valid point if you use apache you can use something like

<!--#include virtual="somefile.html"-->

I think that syntax is right, been a while.

7:57 pm on Dec 20, 2002 (gmt 0)

10+ Year Member



jatar_k: I do use apache--does that make a difference?

littleman: Because I don't know anything about SSI--that's what everyone keeps telling me to use, though. I don't know where to start with it...

8:00 pm on Dec 20, 2002 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



the code I posted above is ssi, though I am not 100% sure of the syntax.

Take a look at this

[httpd.apache.org...]

8:01 pm on Dec 20, 2002 (gmt 0)

WebmasterWorld Senior Member littleman is a WebmasterWorld Top Contributor of All Time 10+ Year Member



SSI is more basic than php or perl.
[httpd.apache.org...]
8:02 pm on Dec 20, 2002 (gmt 0)

WebmasterWorld Senior Member littleman is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Either of the above links should get you going.
8:03 pm on Dec 20, 2002 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



princess, littleman's link is better than mine, more basic tutorial.

thanks littleman

8:06 pm on Dec 20, 2002 (gmt 0)

10+ Year Member



Thanks so much! This should keep me busy for awhile!