While messing with PHP 5.0.0 figured it’s finally time to take at Wez Furlongs Activescript SAPI for PHP. Will the madness never end? ;)
In brief Microsoft provide a mechanism in Windows to “embed” scripting engines (e.g. PHP) and thereby allow execution of code in other languages. More information can be found at MSDN on Windows Script Interfaces.
For PHP the best place for information is the extensive README.
Here’s a quick example which should probably work first time on Win 2000 / Win XP.
1. Download PHP 5 and unzip it somewhere (e.g. C:\php-5.0.0 – you need to create this directory!)
2. From a command prompt;
C:> cd php-5.0.0
C:\php-5.0.0> regsvr32 php5activescript.dll
That’s it. Now the fun begins.
Create a (plain HTML) web page like;
');
foreach ( array_keys($GLOBALS) as $global_var ) {
if ( is_object($GLOBALS[$global_var]) ) {
$document->write($global_var."
");
}
}
View the page in IE and away you go (you should see a list of objects you’d normally use from Javascript).
Now all we need is Microsoft to bundle it with IE ;)
Back to reality, where is actually might be useful is if you want to write Windows sysadmin scripts in PHP.
Update: when posting this thought it would be obvious that this is highly insecure. Make sure you read all the comments below before trying it.
Harry has been working in corporate IT since 1994, with everything from start-ups to Fortune 100 companies. Outside of office hours he runs phpPatterns: a site dedicated to software design with PHP that aims to raise standards of PHP development. He also maintains Dynamically Typed: SitePoint's PHP blog.