Re: newbie questions (2) : Linked PHP scripts?
| From: | Andy Hoffman | Date: | Wed, 30 Aug 2000 13:20:02 +0000 |
| Subject: | Re: newbie questions (2) : Linked PHP scripts? | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-2296@lists.php.net to get a copy of this message | ||
James Duncan wrote:
> I'm new to PHP and it took me two reads before I understood why you were
> trying to do this (at first I thought why not just use PHP in the first
> place - instead of outputting Javascript). Can you give some examples when
> you use this "trick" to aide my understanding further?
>
> Thanks
>
> James
>
> From Andy's original emai:
> In my HTML page, I have a single script line where I want the dynamic
> content to
> be loaded...
>
> <script language="javascript"
> src="myscriptgenerator.php"></script>
>
> NOTE: it doesn't matter that the src tag ends in ".php", since we'll be
> *faking*
> the browser out in a moment.
A good question, with a pretty good answer. I've got a website with a *news*
section (a collection of news briefs with links to larger news stories around
the web) and on the main homepage, I have a php script which fetches the active
news briefs from a MySQL database, organized by departments, and displays a nice
formatted table with headlines and links to the briefs themselves (served up by
another php script/page). All this is done on the homepage through a <?php
include()?> script (as the homepage is a php page itself).
Now, let's say I wanted other people to easily add this "News Section" to their
websites as well, so they could have a dynamic up-to-date news that simply
*loads* from my site. And, since this is a php-script, I don't want to
*require* the other site to have 1) PHP installed - can't count on that -
besides, I'm not about to make a database driven script PUBLIC (passwords and
all) 2) Server side includes - not all web servers have this installed, and I
don't want sites to have to go RENAMING html files to shtml, simply to add my
news section - and the instructions to do this can get quite daunting to novice
web builders. So what's left if you want to give people dynamic PHP scripts if
they don't have php AND they don't use server-side includes? The answer,
Javascript.
And this makes it quite easy for others to add output of your script to ANY html
page. They simply add the <script src="myscript.php3"></script> tags to their
html and the inclusion of dynamic content is off and running.
Hope that helps you understand at least one instance where this might be
useful... I'm sure there are others (for instance, a cheaters way of doing page
counters when you don't have ssi enabled or php (hint: have a perl script output
javascript to display an updated counter value).
--
Andy Hoffman
Web Developer
Bristol-Myers Squibb
email: andy.hoffman@bms.com