View Full Version : using the same HTML code on each page
Steve Sea
07-08-2007, 06:40 AM
Hi All
Just a quick one I am using the same bit of code over and over so can it be placed externally and called as and when needed,
also it's quite a heavy bit of code slowing the page down a bit, would this make it any slower in loading
Great site.
Steve C.
djr33
07-08-2007, 06:56 AM
The code won't do too much to make anything slow, since it's a very small file. Likely, any image, even a small one, will be bigger, so the page itself won't cause much trouble.
As for using the code on each page, that's easy using PHP.
1. You must have PHP installed/enabled on your server.
2. You must have the extension of the file end in .php
3. For any php code it must be surrounded by <?php ..... ?>
4. PHP is parsed by the server, so it will not be output, but rather the result, so with this, just the contents of the included file will be sent, not the php command.
Wherever you want to put the html/text, use this:
<?php include('myincludedfile.ext'); ?>
Simple as that.
Steve Sea
07-08-2007, 08:34 AM
Trying to keep it all client side as its a large form and can be cached local,
is there a way of calling a .htm file in the same manner as a script .js file, I'm messing about with it all but not getting anywhere,
any pointers anyone.
Merci
Steve C
ps. many thanks for the above but grappling with French & HTML is enough languages for me, PNP is a long way off.
Server-side is definitely the way to go. PHP is probably the best-supported, but if you don't want to learn a whole new language you might want to try something like SSI (Server-Side Includes) which is basically a "special set of tags" that can be used to perform some simple server-side operations (such as including files). Your server will need to support it, of course, as with PHP.
djr33
07-08-2007, 12:15 PM
PHP isn't complex at all if you just use includes.
Here's a complex breakdown of everything you need to know:
<?php //open tag
include('path/myfile.ext'); //include will get the contents of another file and output them.
//path/myfile.ext is the location of the file.
//if the file doesn't exist, it will give an error.
/*Close tag >>*/ ?>
Client side for this would be more complex and wouldn't really save anything notable in terms of load for the client or server. It would be more taxing on the browser, as well.
Steve Sea
07-08-2007, 05:30 PM
1stly thanks for the help
I've checked my hosting package and I have php4 en CGI (safe mode off) , php5 en CGI (safe mode off) , + phpMyAdmin, what ever thats for, so I gather I can do the following, I will give it a try and see if it works,
I've tried using this but had some problems with running a script & with spacing issues. but it might help someone else.
<object
type="text/x-scriptlet"
data="your-file-here.htm" height="585" width="600">
</object>
Regards
Steve C.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.