HTA is a Microsoft technology that allows you to deploy an
HTML page consisting of scripts (written in JavaScript or VBScript) as a desktop
application on Windows. The advantage is the efforts and know-how required for
developing the UI of the application, which is same as that for any HTML page
(fire up Dreamweaver and design). The functionality or processing is
imparted through scripting.
|
While you could use ASP objects with standard HTA, PHUI
allows you to use PHP with HTA. PHUI is a set of libraries (PHP and JavaScript)
and a PHP runtime, which allows JavaScipt residing in an HTA to call a PHP
script and get the results from the PHP script. All this happens without
requiring a Web server. Let us write a simple example to see how PHUI works.
The first look
Download PHUI from http://www.phpgeek.com/download /phui-demo.zip. Extract
the zipped file to C:\PHUI. Our 'hello world' HTA is as follows.
APPLICATIONNAME="Hello World"
BORDER="thin" BORDERSTYLE="normal"
CAPTION="yes" MAXIMIZEBUTTON="yes"
MINIMIZEBUTTON="yes" SCROLL="no"
SHOWINTASKBAR="yes" SINGLEINSTANCE="yes"
SYSMENU="yes" VERSION="1"
WINDOWSTATE="normal"/>
Here, the
used to define a HTML Application. For more on HTML applications refer to
http://msdn.microsoft.com/library/default.asp?url=/workshop/author/hta/overview/htaoverview.asp.
Note the inclusion of library.js file as
Save the file as C:\PHUI\userdetails.hta. Note that the
JavaScript here is calling details.php. Below is the code for
details.php.
include("library.php");
$post = $argv<1>;
$_HTA_POST = parse_ini_file($post);
$user = $_HTA_POST<"user">;
$conn = mysql_connect("127.0.0.1","root","secret");
mysql_select_db("pcqdb");
$query = "select email from user where name='$user'";
$query_result = mysql_query($query,$conn);
if(mysql_num_rows($query_result)>0)
{
$row=mysql_fetch_array($query_result,
MYSQL_ASSOC);
hta_return($row<"email">);
}
else
hta_return("not found");
?>
Under the hood, PHUI uses simple text files to pass parameters and the return value amongst the JavaScript & the PHP script |
Note the second and third lines of the PHP code above.
They store the values from the HTML form (the user's name entered in the test
field named user, in our case) in the variable named $_HTA_POST, which can be
subsequently retrieved as:
$user = $_HTA_POST<"user">;
The syntax of the above statement is:
Subsequently, the code connects to a MySQL database server
running on the same Windows machine, queries it and returns the result using
hta_return( ) function, as before. The connection to database and querying is
all standard PHP, and there is nothing specific to PHUI or HTA.
PHUI can be a boon if you want to leverage your PHP
skills in developing small desktop applications or utilities. With
PHUI, you can even meet requirements like having a desktop application similar
to an already developed Web application.
You can reuse the code in your Web application with no or very
less rewriting.
Shekhar Govindarajan, IT4Enterprise