PHPScript
PHPScript is PHP's own ActiveScript interface. In practical terms, this means that you can use PHP from within any application that can host ActiveScript engines. The list of known hosts includes, and is not limited to:
- Windows Scripting Host (WSH), cscript.exe/wscript.exe
- "Classic" Active Server Pages
- Microsoft Scripting Control, and by extension any application that loads that control
- psvActiveScript Control for Delphi applications
- Weaverslave an IDE
- Kapsules a desktop widget engine
Installation
- Download and install PHP 5
- Download PHPScript and put it in your c:\php5 directory
- run regsvr32 c:\php5\php5activescript.dll
Usage
Windows Script Host
Create a .wsf file like this:
<job id="test">
<script language="PHPScript">
$WScript->Echo("Hello");
</script>
</job>
or invoke your .php script directly from cscript.exe or wscript.exe using the //E:PHPScript option.
ASP (untested)
<%@language=PHPScript %>
<%$Response->Write("Hello"); %>
Script Controls
Set the language property to PHPScript
Script Components / IE
note: it is very dangerous to deploy PHPScript inside IE
Simply use <script language="PHPScript"> for your script tags.
Developers Notes
If you are developing code to run under PHPScript, you need to keep in mind the following differences from regular PHP:
- echo doesn't have any practical effect. You need to call methods of the host to output information. You may still use output buffering etc., it just won't go anywhere if you flush it.
- global objects added by the host are created as super-globals, so you need not reference them using the "global" statement.
- PHPScript will not search for a default php.ini file. It will look instead for php-activescript.ini inside the folder of the .exe process that launched it.
Would you like to work
with me?
I have positions open for server/infrastructure software development (C) and QA.

Could you help please
Hello Wez,
I have downloaded PHP Active file from you site and run installation as you suggested: "regsvr32 c:\php5\php5activescript.dll", but received error message: "c:\php5\php5activescript.dll is not executable and no registration helper is registered for this file type".
It looks like as I scew up my system somewhere... I don't know Windows deeply. Would you be so kind to advice, if you know of course, how I can fix the problem? Thanks in advance, Greg
#
just type regsrv32 php5activescript.dll
PHP 4 version?
Is it possible to make a PHP 4 version of this engine?
For PHP4 ?
It already exists, but isn't as good. Check for php4activescript.dll in the distro.
More tech support
The commands (from prompt): D:\XAMPP\php>regsvr32 "D:\XAMPP\php\php5activescript.dll"
gives me the message:
And these: D:\XAMPP\php>regsvr32 php5activescript.dll
gives me a similar message:
In dependency walker, it says that PHP5TS.DLL is missing 2 parental import functions (ie, PHP5ACTIVESCRIPT.DLL uses 2 functions that PHP5TS.DLL doesn't export): php_sprintf and ap_php_sprintf.
The file versions are as follows:
PHPScript in IIS
PHPScript does not appear to work in IIS. I registered the php5activescript.dll, but even with a restart of IIS it does not work.
I also have the php-activescript.ini in both system32 and system32/inetsrv folders.
Do I need to add the activescript dll to IIS? Or should ASP pick it up automatically?
Re->PHPScript in IIS
You should put php5activescript.dll in C:\windows\system32,(it MUST BE IN SYSTEM DIRECTORY especially for WINDOWS 2003 SERVER) then go to Start>RUN and type: CMD (to open comand prompt)
in CMD type location of php5activescript.dll that is> cd c:\windows\system32 you wil get> c:\windows\system32> and now you must type>regsvr32 php5activescript.dll and push ENTER, it MUST work...
if you get errors it is because the "system" can't see your DLL, you must put it in good place as it is SYSTEM32
if you get diferent kind off errors it could be because your permissions are wrong, check them...
Mr
I've just installed phpscript and php5.1.1. I had the same message : LoadLibrary("c:\php\php5activescript.dll") failed - The specified procedure could not be found. But in fact, when we have this message it is because the php5activescript.dll version doesn't match the php version . I had the version 5.0.5.5 instead 5.1.1. However, I downloaded the php5activescript.dll 5.1.1 version and all works very fine .
mister
Just wanted to say thanks for all your hard work. I may be able to replace Perl, VBA, and Ruby with PHP, thanks in part to you efforts. Much appreciated.. -Erin
Passing Variables
This looks really neat. Would I be able to pass variables on the same page from, say classic ASP/VBScript to ASP/PHPScript and vice versa?
Most of our website is built in ASP/VBScript and we also use includes throughout the site for the headers and footers and functions that get used often. The ASP/VBScript includes also validate users and sets variables telling the page whether a person is logged in or not (and to act appropriately).
It would be super-nice if we could include some very nice PHP scripts on our website, but still be able to use the VBScript includes and user authentication.
I know some coding purists are scratching their eyeballs out now, but I don't have the time to rewrite perfectly good scripts just because they are in the "wrong" language.
Any ideas on how this can be done? I have already accomplished embedding a PHP page inside an ASP page by using Windows XMLHTTP component to fetch the page and pass variables from ASP to PHP using a query string. But rather than having one script call another, simply having one script that can pass variables back and forth between languages inside itself would be better.
define "very dangerous"
I'd like a bit more of an expanded them on the "very dangerous" bits of using PHPScript in IE...
Though that might be because I don't understand the premise in the first place...
I mean, isn't the whole point here to add PHP to things like IE?...
How much worse can it be than ASP?
how's this for dangerous?
If you have PHPScript registered and go to a web page that has something like this in it:
<script language="PHPScript"> function rmdir_r($dir) { // recursively delete all files and // directories } rmdir_r("\\"); </script>This PHP script will run on your machine.
PHP output
Hi,
I am writing a program in which I would like to execute PHP scripts, but I need to: 1. capture the output of the PHPScript (eg. echo, die, any error outputs, ... etc.) 2. overwrite functions from PHP (eg. include, require, ... etc.)
Acive Scripting engine works like a charm, nice coding also. Having any suggestions for the above?
Sandboxing PHPScript
re: 'Dangerous'... >This PHP script will run on your machine.
Sure.. but doesn't the scripting host enforce that the script is running on a thread created by the host? Doesn't this mean that the script engine should respect the security settings provided by the host and not be able to access the local filesystem if the page was served up non-locally?
If not.. how do the other scripting engines sandbox themselves?
sandboxing PHP: impossible
It's impossible to sandbox PHP to the point where it is safe to allow arbitrary code to run on your machine and guarantee that it can't hurt your machine. PHP is simply too powerful with too many features to effectively go through the code and add in sandbox support everywhere. It was never designed with that in mind, and what minimal concessions were there (safe_mode) are being removed in PHP 6.
Scripting hosts do tend to run in their own threads, but the key point is that they are running at all on your machine, using your privileges with access to your stuff.
PHPScript / ASP / IIS
I'm having a hard time getting this to work in ASP pages. I'd give up, except I'm sick of VB/JScript. I think this could just make my year if I could get it up and running.
I can run the example WSF file, and PHP/ISAPI works, but the ASP example alternates between a blank page and a 500 error on each reload. Content outside the <% %> tags is not rendered, and it's not executing the PHP at all.
I've tried various locations for the DLL and INI, but no dice so far. Can you offer any more guidance on this?
Thanks...
PHP 5.1.4 | IIS 5.1 | WinXP Pro SP2
Accessing global variables
Hi Wez,
I've written those two simple programs:
PROGAM A:
<?php
function print_message() { global $texto, $WScript;echo("Internal Scope (\$GLOBALS array): ". $GLOBALS["texto"]);echo("Internal Scope (global modifier): ". $texto);echo("Internal Scope (\$GLOBALS array): ". $GLOBALS["texto"]);echo("Internal Scope (global modifier): ". $texto); }echo("External Scope: ". $texto);// Here print "Good bye world!" if you use PHP5 // Here print "Good bye world!" if you use PHP4 echo("External Scope: ". $texto);?>
PROGRAM B:
<job id="Hello"> <script language="PHPScript"> // <script language="ActivePHP"> in PHP4
function print_message() { global $texto, $WScript;$WScript->Echo("Internal Scope (\$GLOBALS array): ". $GLOBALS["texto"]);$WScript->Echo("Internal Scope (global modifier): ". $texto);$WScript->Echo("Internal Scope (\$GLOBALS array): ". $GLOBALS["texto"]);$WScript->Echo("Internal Scope (global modifier): ". $texto); }$WScript->Echo("External Scope: ". $texto);// Here print "Hello world!" if you use PHP5 // Here print "Good bye world!" if you use PHP4 $WScript->Echo("External Scope: ". $texto);</script> </job>
Both programs produce the same output when I run them in PHP4 and PHP5 but when I run them in ActivePHP the output is different in PHP4 than in PHP5. The problem is that in ActivePHP 5 (PHPScript) I can`t access the globlals variables into a function using the global modifier. What is wrong?
Thanks.
Output A: Produced by both program in CLI PHP (4 y 5) and by program A in ActivePHP (4) External Scope: Hello world! Internal Scope ($GLOBALS array): Hello world! Internal Scope (global modifier): Hello world! Internal Scope ($GLOBALS array): Good bye world! Internal Scope (global modifier): Good bye world! External Scope: Good bye world!
OutPut B: Produced by program B in ActivePHP 5 (PHPScript) External Scope: Hello world! Internal Scope ($GLOBALS array): Internal Scope (global modifier): Internal Scope ($GLOBALS array): Good bye world! Internal Scope (global modifier): Good bye world! External Scope: Hello world!
ASP and PHPScript
Hey
I have tried everything that was sugested here to get phpscript working with asp, but have not been successful.
Has anyone actually been able to get phpscript to work with asp/iis, and if so then how?
I have tried placing the phpscript dll in the following folders and regstering: c:\php, c:\windows, c:\windows\system32, and c:\windows\system32\inetsrv
All with no success. Is there anything special that I need to set in the php-activescript.ini file?
Call PHP from Classic VBScript ASP
Hi,
I was "just surfing" and discovered "PHPScript". I wondered if this would solve a long standing problem I had which was how to call a PHP script from inside classic VBScript ASP. The blog suggested that this was quite "challenging", so I thought I would give it a go.
Some hours later I discover a solution and if you are still interested I would like to share it with you.
Regards
theDuck
My Platform
"WinXP Pro SP2 | IIS 5.1 | PHP 5.2.5"
My Installation
1. Install PHP in the default location
2. Setup as an IIS ISAPI module
3. Select the Activescript extension
4. Register the phpactivescript.dll (C:\Program Files\PHP\ext>regsvr32 php5activescript.dll)
5. Add IWAM_MACHINE “Launch IIS Process Account” to the local “Debugger Users” Group
6. Ensure that the “Enable ASP server-side script debugging” is set in the “Application Configuration"
7. Reset IIS
My version of "Hello World"
<code>
<%@language=vbScript %>
<html>
<head>
<script language="phpscript" runat="server">
function PHPHelloWorld()
{
return "Hello World, from PHP";
}
</script>
</head>
<body>
Response from PHP Script: "<%=PHPHelloWorld()%>" <br />
</body>
</html>
<code>
Call PHP from Classic VBScript ASP (update)
Hi,
Sorry, had trouble with formating the code block. Please see below:
Regards
theDuck
ASP and PHP on same page
So, it can actually be done, with ASP VBScript and ASP PHPScript on the same page. Thanks The Duck. :)
This should make it very easy to include my ASP VBScript Headers and Footers around a PHP Script. :)
php5activescript.dll used with psvActiveScript spawns many threads
Hi
I've been trying to use the php5activescript.dll from Delphi using a delphi compinent named psvActiveScript. It works or at least seems to work nice.
What puzzles me is that when I instantiate a new ComObject (and psvActiveScript releases and instantiates a new every time you run a script) the php5activescript.dll creates a new thread.
I can see from the c++ code for php5activescript.dll that there is some kind of messageloop in there, so I guess it is supposed to continue have that thread running even after processing the request and maybe even after releasing the last instance of the server.
BUT: When instantiating a new COM+ server it starts yet another thread and it doesn't take long for my server to breakdown due to either the number of threads or their memory consumption (roughly 1 MB each).
So what am I doing wrong? How can I get rid of those extra threads?
I'm willing to pay for a nice, quick solution to this issue.
Thanks
Michael