PHP in a Browser!!!

Originally published: 06/2004 by J Wynia

I was messing around with ActivePHP, as I've been contemplating adding its
setup to the Sokkit install. Anyway, the given examples don't work on my
current machine. I'll try them on some others, but it seems to boil down
to the fact that the normal input/output methods don't work. For instance,
you can't do anything with the window object like any sort of alert(). You
also can't seem to do anything with the document object like a write(). I
first thought that the PHP wasn't doing anything, but then I created the
following HTA file (save this code as test.hta or something and double
click) that dumps out the contents of the $GLOBALS variable. Lo and
behold, it worked. However, none of the browser stuff is in there.


<HTML>
<HEAD>
<TITLE></TITLE>
<HTA:APPLICATION ID="oHTA"
APPLICATIONNAME="RSS Evaluator"
BORDER="thin"
BORDERSTYLE="normal"
CAPTION="yes"
ICON=""
MAXIMIZEBUTTON="yes"
MINIMIZEBUTTON="yes"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="yes"
VERSION="3.5"
WINDOWSTATE="normal"
/>


<script language="ActivePHP">
function write_file(){
$filename = 'test.txt';
$somecontent = print_r($GLOBALS,true);

if (!$handle = fopen($filename, 'w')) {
print "Cannot open file ($filename)";
exit;
}

// Write $somecontent to our opened file.
if (!fwrite($handle, $somecontent)) {
print "Cannot write to file ($filename)";
exit;
}

print "Success, wrote ($somecontent) to file ($filename)";

fclose($handle);
return "Success";
}

</script>


</HEAD>
<BODY bgcolor="menu" scroll="no">

<button onclick="write_file();return false;">Function
Test</a>

</BODY>


Then, I was wondering if you can pass values between Javascript and
ActivePHP script. After all, in that case, you could do the heavy lifting
with PHP and interact with the user using Javascript to manipulate the
HTML/CSS. Well, it turns out that, while you can pass data, use functions,
etc. across Javascript/VBScript, you can't do the same thing with
ActivePHP. Not sure why.

At any rate, I think that the use of ActivePHP and HTA's is a promising
way to do quick and easy GUI apps with PHP and would like to see progress
made on these fronts. Anyone who has more information or can come up with
a way past these barriers, let me know.

Comments

J Wynia on 8/13/2004
Incidentally, PHP5 fixes access to the browser objects. There's a more recent article on this site detailing that experiment.
blog comments powered by Disqus
Or, browse the archives.
© 2003- 2013 J Wynia. Very Few Rights Reserved. This article is licensed under the terms of the Creative Commons Attribution License. Quoted content or content included from others is not subject to that license and defaults to normal copyright.