Forum Moderators: coopster
document.write(<the html>). require_once(<url for file containing the html fragment>); will have the same affect. [edited by: jatar_k at 4:29 pm (utc) on April 14, 2005]
[edit reason] no urls thanks [/edit]
Server-side operations (like PHP) are always more reliable. If you are concerned about delaying the page delivery or increasing the server's processor load by using the PHP solution, there will be virtually no difference (ok, a tiny bit more processor load with PHP ... but really negligible) between using PHP or Javascript for this.
PLUS, using PHP to include the code offers the opportunity for you to re-use code quite simply. Where with Javascript you would need to alter the document.write() text on each page that includes it, with PHP you would only need to change the one required file, and then every page that uses it will automatically be updated.
Oh ... and welcome to WebmasterWorld! :)
is there a simple way to set up testing-only server-software on my local machine so i can debug php locally before uploading them to site's server?
What kind of site server are you running? You need to duplicate that setup on your testing machine. If you use MS IIS, then install IIS on your testing machine. If you use Apache, then it needs to be installed.
Once your server is installed, download and install PHP for that server, start the server, and browse to [127.0.0.1...] to view your local website.
With the Apache option, there are several "ez-install" packages available that will install both Apache and PHP (and MySQL database server, if you like). With IIS, you'll need to download the Windows PHP file(s) and install them separately.
StupidScript said:PLUS, using PHP to include the code offers the opportunity for you to re-use code quite simply. Where with Javascript you would need to alter the document.write() text on each page that includes it, with PHP you would only need to change the one required file, and then every page that uses it will automatically be updated.
Well actually, I find the .js solution simpler - I probably wasn't clear: say I have a fragment of html for a banner to appear on each page. I put a
<script type="text/javascript">embedbanner();</script> tag on each site page then in my .js file i have function embedbanner(){document.write('<all the html for the banner>')}. So if I change the banner, I only need to change it once in the .js file. I say i find it easier than a require_once("<url to file containing banner html fragment>") because I can have several such embed functions in the same .js file(like a footer, nav, etc) whereas I (think) I need one file for each frag if I used the PHP solution. Also - having one central js file with all these embedXXX() functions linked in the <head> means its cached no? <embarrased>Thanks for the server-software info - I have a lot to learn though to understand your advice. e.g. How to find server info?(it's apache, I think), where to get ez-install pks, etc. </embarrased>
Here's an example of a PHP solution, like that:
INIT.PHP
<?php $topbanner="banner.php?id=top"; $midbanner="banner.php?id=mid"; $lowbanner="banner.php?id=low"; ?> PAGE1.HTML
<?php include "init.php"?> Top Stuff ... <?php include $topbanner?> Body Stuff ... <?php include $midbanner?> Footer Stuff ... <?php include $lowbanner?> BANNER.PHP
<?php switch ($_POST["id"]) { case "top": echo "Top banner text"; break; case "mid": echo "Mid banner text"; break; case "low": echo "Footer banner text"; break; } ?> You end up with (1) init file that sets up the top, mid and footer banner text references (this is new and more than you currently use, but you never need to touch this file again) and (1) banner file that behaves similarly to your included .JS file (provides different text depending on which banner position).
Then, similarly to what you are doing with Javascript, you indicate in your "real" page where the banner is to go, and which one to use. init and banner take care of the rest.
You make your changes to banner.php for the whole site.
Re: ez-install packages
While there are several out there which work very well, might I suggest XAMPP [apachefriends.org]? It's free, quite robust and very easy to install...
[edited by: StupidScript at 11:03 pm (utc) on April 14, 2005]
Some search engines count the words in your SCRIPT tags as part of the whole page content, which, of course, is less than useful to your keyword density figures.
Using PHP eliminates this possibility. All those search engines will see is the result of the PHP operation, no "extra" characters to clog up/diminish your search engine placement work. It also makes each page slightly smaller for the download.
(1 character = ~1 byte:
<script type="text/javascript" language="javascript">
</script>