View Single Post

  #8 (permalink)  
Old 12-08-2007
Csaba Gabor
 
Posts: n/a
Default Re: Running PHP via CLI

Jean Pierre Daviau wrote:
>> as opposed to having a nice web interface for it on a
>> standalone machine. As you probably know, you can
>> configure your browsers so that putting in word like
>> phpadmin into the address bar will redirect it to a
>> local file (instead of the web at large).

>
> ??


That's actually two distinct question marks for
two distinct questions, I suppose.

> On window? How do you do that?


First question...
Look at the file:
C:\Windows\System32\drivers\etc\hosts
You can then make a line like:
127.0.0.1 phpadmin
When you type phpadmin into the address bar of any
browser (such as phpadmin/myscript.php, you'll get
directed to localhost, but then it's up to the web
server to figure out what to do (but it need not
be accessible from the web) with your request (ie.
you can have a virtual domain)

> This would permit to show a php file with IExplorer without
> Apache or else?


Now this is the harder question (in my opinion).
Good news, bad news. The good news is that it's
possible. The bad news is that the setup is
non trivial. Better to use apache locally.

However, if your religion prevented you from
installing a web server, then you might think to
create a local .htm file whose only job was to
run your php script through php-cgi.exe, say,
then collect the output and then blat it out
to web browser.

But this is not a nice solution because for every
php file you would have to create a separate
..htm file that called the .php file and then you
wouldn't be typing in c:\mypath\myscript.php
anymore, you'd be putting in c:\mypath\myscript.htm
Of course you could put everything into myscript.php
properly wrapped and escaped, but this is really
no longer a nice .php script file anymore.

There is a second approach which is more fruitful,
I think. Put a handler into a dummy page that you
start up with so that when you would navigate away
to another page, if that new page is a local .php
script, then the navigation is aborted, the .php
script is run, the output is collected, and then
the document is replaced. As far as I can figure,
however, you can't get to the url that you would be
navigating to through js, so a window.onbeforeunload
won't work.

However, the appropriate events can be hooked and
handled in ie itself, as opposed to the window or
document object, but the scope of that is beyond
this post. As I say, better to have the web
server run locally.

Csaba Gabor from Vienna
Reply With Quote