...

View Full Version : Creating Protocol for PHP



Andrew-J2000
05-12-2004, 03:23 AM
This is probably an extremely stupid question to put here, but I am just toying about with Windows and PHP.

I can manage to execute PHP from its own protocol, however I cannot return a stream back to the browser...



<a href="php://phpinfo();" title="PHP">phpinfo();</a>
or in the browser as php://phpinfo();

Now you must be thinking wtf, lol.

Introduction...



Registering an Application to a URL Protocol

To enable an application to handle a particular URL protocol, you must add a new key, with the appropriate keys and values, to the registry in HKEY_CLASSES_ROOT.

The new registry key must match the protocol scheme that is being added. For instance, to add the protocol note:, the key added to HKEY_CLASSES_ROOT should be note. Under this new key, the Default string value should be the name of the new protocol, and the URLProtocol string value should contain either protocol-specific information or an empty string. Also under the new key, a DefaultIcon key and a shell key should be added. The Default string value under the DefaultIcon key must be the file name to use as an icon for this new URL protocol. Under the shell key, a key using a verb (such as open) should be added. A command key and a DDEEXEC key can be added under the key using a verb. The values under the command and DDEEXEC keys are used to call the application.



[HKEY_CLASSES_ROOT\php]
@="\"URL: php Protocol\""
"URL Protocol"=""
[HKEY_CLASSES_ROOT\php\shell]
[HKEY_CLASSES_ROOT\php\shell\open]
[HKEY_CLASSES_ROOT\php\shell\open\command]
@="php.exe -r %"

Problem: Using php.exe -r %1, passes everything including the protocol, for example php://phpinfo(); /



Now whilst, I don’t think I can use PHP directly, I have tried an alternative method by using Jscript (WSH) as an intermediary and executing PHP. Now whilst I can manage to get a JScript echo (alert), I have been racking my brain for a way to actually, write/hook into the browser. It works exactly the same way as <a href=”java_script_:..”> works, so how can I actually, write to the browser from an external JScript via the PHP protocols call?

I have tried a number of methods, to actually do this, however using the following doesn’t work…

window.document.write
WScript.StdOut.Write('test');

There is one more method that I can think off, which is something along the lines of…. external …

Any Ideas anyone? Not, that you probably all think i'm crazy now.

firepages
05-12-2004, 05:00 AM
I don't think you can do what you are trying to do , e.g pipe the results of the PHP stream to your browser without rewriting IE etc

the best you will get is to start an instance of PHP in which you can then parse $argv & do whatever (an interesting idea all on its own !) note that in later versions of PHP register_argv is disabled in the php.ini by default.

all you can do (and its mostly pointless if you have a webserver running) is say create a deamon in PHP serving a given socket & then call that for output say <img src="http://localhost:6969" /> , its a nice way of running a background script when no server is available (PHP is the server here)

I must say thanks BTW cos thats a great idea for another project I have , just gotta find out how to do the same in *NIX ...

Andrew-J2000
05-12-2004, 06:44 AM
I don't think you can do what you are trying to do , e.g pipe the results of the PHP stream to your browser without rewriting IE etc
the best you will get is to start an instance of PHP in which you can then parse $argv & do whatever (an interesting idea all on its own !) note that in later versions of PHP register_argv is disabled in the php.ini by default.
all you can do (and its mostly pointless if you have a webserver running) is say create a deamon in PHP serving a given socket & then call that for output say <img src="http://localhost:6969" /> , its a nice way of running a background script when no server is available (PHP is the server here)
I must say thanks BTW cos thats a great idea for another project I have , just gotta find out how to do the same in *NIX ...

I believe otherwise, the reason being is that I very much doubt JavaScript is built into iexplore directly here is why (%Systemroot%/system32/jscript.dll). JavaScript or JScript in Microsoft’s instance, works in exactly the same manner, for example using the address bar of a href attribute with ‘javascript:’ prefixed, works exactly the same.

PHP would have to execute a predefined script, prior, to accepting the parameters from the PHP protocol, due to the fact that the entire string in the HTML attribute is parsed e.g. ‘php://phpinfo();’. So you essentially have to buffer and parse and eval the command, yuck!

Hmmm, I think you are confusing what I am actually, referring too. I was actually, looking at embedding PHP on the client side browser, via registering the php protocol. Essentially, to see if it was possible, and the more I look into it the more I believe it is possible :) . Although an interface may be required, to hook php back into the current instance of the browser (HWND) and use com as an interface for the current window. As you know, we can execute applications via com, eg…


<?php
class IESink {
var $terminated = false;
function OnQuit() { $this->terminated = true; }
}
$sink = new IESink;
$ie = new COM("InternetExplorer.Application");
com_event_sink($ie, $sink, "DWebBrowserEvents2"); //IShellWindows
$ie->Visible = true;
$ie->Navigate("http://www.php.net/");
while( $IE->Busy ) {
sleep(1);
}
while (!$sink->terminated) {
com_message_pump(4000);
}
?>



Part of reasoning for this is due to a programming language called REBOL. Take a look at this... http://www.devx.com/webdev/Article/17120/1954?pf=true

I had a quick search for you with regard to registering protocols on nix, however I don't think the docs I found were very relevent, more todo with network stacks. Anyway, fancy explaining a little about this project, as i'm not sure we had quite the same idea?

Well, I couldn't see what you were refering to exactly, which confused me slightly.

all you can do (and its mostly pointless if you have a webserver running) is say create a deamon in PHP serving a given socket & then call that for output say <img src="http://localhost:6969" /> , its a nice way of running a background script when no server is available (PHP is the server here)

firepages
05-12-2004, 07:47 AM
I very much doubt JavaScript is built into iexplore directly

nor do I , but don't confuse what is happening when you type javascript://blah into IE/moz with what happens when inside a webpage you use <sript src="" as there are 2 different things happening there altogether.

I don't pretend to know how JavaScript is called within IE , but am pretty sure that it has nothing to do with the javascript protocol, actually Alex Vincent may have a better idea (from a Moz perspective) perhaps he will read this , I don't see that COM is relevant here either.

for embedding PHP in any other compiled application you need to be looking at the php_embed.sapi , I know for instance you can compile PHP scripting into MySQL myphp (http://talks.php.net/show/myphp/0) , there are other talks on embedding in talks.php.net somewhere

my project concerns an issue with launching php-gtk GUI's applications from within IE & Moz , currently links to executables require 3rd party tools to run onclick from within IE , nor can I find any workarounds for gecko, but the idea of <a href="php-gtk://app_to_run"> is a corker ! and appears to work , also from the command line as noted in the rebol link , so cheers for that !

I do remember talk of <script src="php"></script> with the advent of the embed sapi though I have heard no more of it since.

Andrew-J2000
05-12-2004, 09:57 AM
We can only guess how it works, unless we actually find out :thumbsup:, the reason I mentioned Com; although a v.nasty idea, was a way to dump the output into IE/Automate IE, from PHP.


$ie->Navigate("http://www.php.net/");
while( $IE->Busy ) {
sleep(1);
}
$ie->document->innerHTML=var_dump($this);


The reason for this is because my knowledge of C is zero (so embedding is out of the question, unless I did something in C#), whilst I was only toying with the notion, i'm glad it gave someone some inspiration.

I beleive you will enjoy this too... [http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/html/winforms05152003.asp?frame=true]



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum