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

Mark Rogers mark at quarella.co.uk
Tue Dec 4 14:43:35 GMT 2007


Dave Crisp wrote:
> The HTML <script> tag is for embedding JavaScript; you cant include a
> PHP file that way IIRC.
>
> Try renaming the html file to have a .php extension, and then replace
> the <script> ... </script> with "<?php
> include('http://www.suffolk-ancestor-genealogy-research.co.uk/counters/counter.php?webpage=main'); ?>
>   

Based on the OP's choice of Subject ("... *remote* PHP script...") I 
assume that the calling code should not be assumed to be on the same 
server, and therefore should not be assumed to be running PHP (although 
clearly in the OP's example the host is the same). It looks like an 
attempt to build a fairly standard counter script (a good way to learn 
some PHP, by the way).

Brett's Javascript is the best way to do this without changing the 
counter script, IMHO.

On the other hand, assuming that changing the counter script is OK, I am 
guessing that the script ends something like:
    echo $counter;
.. which could be replaced by:
    echo "document.write($counter);";
.. to turn it into a Javascript response that the OP's HTML could use 
unchanged.

Or:
    if (!empty($_GET['js']))
        echo "document.write($counter);";
    else
       echo $counter;

.. then change the HTML from:
    <script 
src="http://www.suffolk-ancestor-genealogy-research.co.uk/counters/counter.php?webpage=main"></script>
.. to ..
    <script 
src="http://www.suffolk-ancestor-genealogy-research.co.uk/counters/counter.php?js=1&webpage=main"></script>

That way, whether or not it outputs the script instead of the raw value 
is configurable depending on the parameters passed to the counter script.

Any or all of the suggestions in this thread will work of-course, and to 
the OP: "welcome to PHP!"

-- 
Mark Rogers // More Solutions Ltd (Peterborough Office) // 0845 45 89 555
Registered in England (0456 0902) at 13 Clarke Rd, Milton Keynes, MK1 1LG




More information about the main mailing list