[ALUG] How to display result of remote PHP script within a HTML page

Brett Parker iDunno at sommitrealweird.co.uk
Tue Dec 4 11:36:40 GMT 2007


On Tue, Dec 04, 2007 at 10:25:09AM -0000, sagr wrote:
> Hi folks.
> 
> A very dumb question from a HTML / PHP beginner...
> 
> I have written a simple hit counter prog which I can access by running:
> http://www.suffolk-ancestor-genealogy-research.co.uk/counters/counter.php?webpage=main
> 
> I now want to integrate this into a HTML website page, so that this remote
> script "counter.php" is run and the result displayed on the HTML webpage
> each time the page is viewed.
> 
> I have created a simple HTML page:
> http://www.suffolk-ancestor-genealogy-research.co.uk/counters/count_page.html
> 
> which just consists of:
> 
> <HTML>
> <BODY>
> <script
> src="http://www.suffolk-ancestor-genealogy-research.co.uk/counters/counter.php?webpage=main"></script>
> </BODY>
> </HTML>
> 
> When I go to this count_page.html webpage the hit counter is incremented but
> the result is not displayed on the webpage (even though it's output is
> visible when I run the script counter.php directly).

<script> doesn't do what you appear to think it does. It points to a
location for a javascript file (or other supported scripting language),
you are not getting back a javascript file, you're getting some numbers.

You should be able to do something like:
	<script language="javascript">
		url = "http://www.suffolk-ancestor-genealogy-research.co.uk/counters/counter.php?webpage=main"
		reqObj = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP.3.0");
		reqObj.open("GET", url, false);
		reqObj.send("");
		count = reqObj.responseText();
		document.write(count);
	</script>

Or... you could use something like SSI to call it.

Cheers,
-- 
Brett Parker



More information about the main mailing list