Copy link to clipboard
Copied
Suppose I have a set of links or just plain text, which is identical across multiple html pages. Is there a way to 'encapsulate' that into one file, which is separately maintained, and which can then be called on every page that needs to have it? Hope that is clear.
The simplest way to do that would be by using server side includes...
1. Save your pages that will have includes with .php extensions (servers don't normally parse php in .html files, but you can do that, pretty easily, if your hosting company allows it)
2. Create an empty file that will have only the code of the item(s) you want to include. For example, if it's a group of links, the file will only have the <a href=... code and text for the links, no <html>, <head>, <body> or other code that norma
Copy link to clipboard
Copied
The simplest way to do that would be by using server side includes...
1. Save your pages that will have includes with .php extensions (servers don't normally parse php in .html files, but you can do that, pretty easily, if your hosting company allows it)
2. Create an empty file that will have only the code of the item(s) you want to include. For example, if it's a group of links, the file will only have the <a href=... code and text for the links, no <html>, <head>, <body> or other code that normally appears in a full page. Includes are just fragments being added into the page, not complete pages.
3. Save that file into an includes folder in your site for organizational purposes...
includes
header.php
navigation.php
text.php
4. Add a php include statement into the code of the page that you want your server to add it to, where you want it added. The server will replace the include statement with all code from the include file, so inserting it in the correct location is important. With the above folder structure and example pages, the include statement would something look like...
<?php include 'includes/navigation.php' ; ?>
Wherever you put that small snip of code, all code from the navigation.php file will be written in its place.
5. Upload your pages and include folder to the server. As long as you have PHP installed (most servers do), the include's file will be written into every page that it appears on, automatically when your viewers pull them up. If you ever want to change something site-wide, all you need to do is update and upload the include file. The server will push your updates automatically to every page that has a given include statement.
Copy link to clipboard
Copied
This is Looking very promising. Next question: can I pass parameters to the php? That would make ever smooch more useful for my present purpose (showing jpg images in sequence).
With thanks in advance,
jwc
Copy link to clipboard
Copied
You can do just about anything with php, from simple includes like the above to an entirely database driven website with ecommerce.
If you start a new thread about the type of script you want to make, I'm sure one of the resident php gurus can point you in the right direction.
Copy link to clipboard
Copied
You can pass variables to and from the include files in several ways. At this point you should probably start studying basic PHP, but here are some ways to pass variables.
Pass a variable using a URL parameter like this: mypage.php?myvariable=apple. You then retrieve the variable like this: $myvariable = $_GET['myvariable'];
Pass a variable in the POST or SESSION array
Copy link to clipboard
Copied
To parse PHP includes on shared hosting that supports PHP code, your parent pages need a .php extension. However the include files themselves can be named anything you wish: foo.html or foo.php, or foo.whatever
Nancy
Copy link to clipboard
Copied
Thanks, Nancy; this looks very promising. Will respond further after implementing and testing (may be a while; several files to work on).
jwc