homepage Welcome to WebmasterWorld Guest from 54.161.202.234
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
PHP +same content on all pages of a site
same content on all pages of a site
princess




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

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?

 

jatar_k




msg:1278393
 7:21 pm on Dec 20, 2002 (gmt 0)

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";
?>

princess




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

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?

littleman




msg:1278395
 7:50 pm on Dec 20, 2002 (gmt 0)

Princess, just curious -- why not just use ssi?

jatar_k




msg:1278396
 7:52 pm on Dec 20, 2002 (gmt 0)

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.

jatar_k




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

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.

princess




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

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...

jatar_k




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

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

Take a look at this

[httpd.apache.org...]

littleman




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

SSI is more basic than php or perl.
[httpd.apache.org...]

littleman




msg:1278401
 8:02 pm on Dec 20, 2002 (gmt 0)

Either of the above links should get you going.

jatar_k




msg:1278402
 8:03 pm on Dec 20, 2002 (gmt 0)

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

thanks littleman

princess




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

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved