If I put PHP script in the "data" directory can I use it in my Firefox add-on?
Firefox add-ons can only execute JavaScript. This still leaves you with a few options:
Rewrite the PHP code in javascript by hand
Rewrite the PHP code in javascript by hand, using a library like phpjs which emulate PHPfunctions in javascript
Use a PHP-to-JavaScript transpiler to convert the code (might only work for simple code)
use a PHP interpreter that is written in JavaScript, like this one and execute the PHP script
(I just googled those links and have no idea how well they work, there probably are better alternatives)
A rewrite of the PHP code is the only clean way in my opinion. Carefully migrating the most basic code with a transpiler might save some time though.
Firefox CANNOT use php in extension directly, unless you indirectly call your php code via XPCOM or other workaround.
Related
I am trying to write program in PHP, which would download and parse html source. Problem is, when I try to download html, which is generated by js.
Is there any chance to download the file after function onload() is completed?
Thanks
Not a trivial task as Javascript is actual active code that has to be interpreted by the browser. What you get from the server is the actual HTML, and all the things that javascript does is on the client side and is completely out of the hands of the server who is giving you the Web page. You can't solve this in general with static analysis (ie guessing what will happen by looking at the code without actually executing it). The only way to reliably do this is to actually execute the javascript.
That being said, you probably don't want to write your own javascript interpreter from scratch. There are "headless" implementations out there that have a javascript interpreter just like a browser does but doesn't display it on a screen - it does all the operations on a virtual DOM. Try looking into PhantomJS.
EDIT See this question where someone basically does what you are asking.I think it should work as-is for your case.
I don't know of any "pure" php solutions, but you could easily automate running the script with php. If you need to stay PHP due to any reason then "headless DOM renderer" is what I would search for.
Is there anyway to get Perl Cgi session information within PHP? Most of the site I'm working on is programmed in Perl, except for a small portion. This portion uses PHP instead, and I was wondering how I could use the Perl CGI Session information from within PHP.
I was thinking of executing a perl script upon entering the page through exec that verified the session information, but I was hoping there was a better way to access the session variables, preferably one that would work without the use of exec.
Any suggestions?
If it helps, the segment that's in PHP is loaded within an iframe on the page. I'm using Perl's CGI:Session module to create the sessions.
If you need anymore information, just let me know.
https://metacpan.org/module/CGI::Session::Serialize::php
You init call would be something like this:
my $session = CGI::Session->new( 'serializer:php' );
I am not 100% sure on the php side. CGI::Session::Serialize::php uses https://metacpan.org/module/PHP::Session so it may just work automatically with php. If not you will have to point php to the perl session file.
One more edit.
If that does not work you could use https://metacpan.org/module/CGI::Session::Serialize::yaml
Then have php parse it http://php.net/manual/en/book.yaml.php
I really want to mix Lua and PHP, for example receive a PHP query and process some parts of the query using Lua scripts (being called from the PHP script that got the initial query ).
Any clues about this ? I've seen some libraries to use Lua as some kind of PHP replacement, but I've seen nothing clear about how to use both Lua and PHP together.
Thanks
Have you seen phplua? It looks like it could do what you want. I found it via the Lua binding-with-other-languages page (it was the only relevant option, for better or worse).
There is now a full PECL extension for embedding and interacting with Lua code.
See http://pecl.php.net/package/lua and http://www.php.net/manual/en/book.lua.php
I assume you aren't feeling up to embedding lua in PHP which leaves running lua as an external script and reading the result. That's a pretty common operation and this page provides some guidance.
I have this nice big Dev Kit written in PHP, but the application I'm currently developing is in CFML.
In an attempt to avoid rewriting the PHP, I'm going to try to just wrap the PHP in CF <script> tags and call the PHP functions when I need them.
Does anyone have any idea how to call one of those PHP functions inline in CF?
There's no built-in way to do this, but using CFGroovy (which allows you to inline any Java Scripting API-compliant language implementation) and Quercus (a PHP implementation in Java), you may be able to pull off what you want/
CFGroovy: http://www.barneyb.com/barneyblog/projects/cfgroovy2/
Quercus: http://www.caucho.com/resin-3.0/quercus/
A simple example including source code:
http://www.barneyb.com/cfgroovy2/
You can't. It's a whole other app engine. You could use CFHTTP to call a PHP page - but it's a bit overkill. You can look at Sean's solution here:
http://corfield.org/entry/ColdFusion_8_running_PHP
Edward M. Smith is right. You may be able to mix PHP and CFML by using Resin as your JVM. While I have not done so, I do believe it is possible to have Resin interpret your PHP code from within the same context as a CFML (ColdFusion) Web site.
A .cfm/.cfc could not contain any PHP and a .php file could not contain any CFML/CFScript;
however, those files could live side by side within your www.something.com domain.
Resin http://www.caucho.com/ is a Web Server/PHP Interpreter that is very fast and written in Java. It is the bundled JVM for the open source CFML project Railo.
Hope this helps.
You can pass data back and forth by having php/coldfusion store/retrieve client array's or variables.
One other choice is to force coldfusion to parse through .php files, for any coldfusion inside there. How it would handle the mixture of coldfusion and php, I am not sure...
I am writing a small web server, nothing fancy, I basically just want to be able to show some files. I would like to use PHP though, and im wondering if just putting the php code inside of the html will be fine, or if I need to actually use some type of PHP library?
http://www.adp-gmbh.ch/win/misc/webserver.html
I just downloaded that and I am going to use that to work off of. Basically I am writing a serverside game plugin that will allow game server owners to access a web control panel for their server. Some features would be possible with PHP so this is my goal. Any help would be appreciated, thanks!
The PHP won't serve itself. What happens in a web server like Apache is before the PHP is served to the user it is passed through a PHP parser. That PHP parser reads, understands and executes anything between (or even ) tags depending on configuration. The resultant output, usually still HTML, is served by the web server.
There are a number of ways to achieve this. Modules to process PHP have been written by Apache but you do not have to use these. PHP.exe on windows, installed from windows.php.net, will do this for you. Given a PHP file as an argument it will parse the PHP and spit the result back out on the standard output.
So, one option for you is to start PHP.exe from within your web server with a re-directed standard output to your program, and serve the result.
How to create a child process with re-directed IO: http://msdn.microsoft.com/en-us/library/ms682499%28VS.85%29.aspx however, you won't be writing the child process, that'll be PHP.exe
Caveat: I am not sure from a security / in production use perspective if this is the most secure approach, but it would work.
PHP needs to be processed by the PHP runtime. I'm assuming the case you're talking about is that you have a C++ server answering HTTP queries, and you want to write PHP code out with the HTML when you respond to clients.
I'm not aware of any general-purpose PHP library. The most straightforward solution is probably to use PHP as a CGI program.
Here's a link that might be useful for that: http://osdir.com/ml/php-general/2009-06/msg00473.html
This method is nice because you don't need to write the HTML+PHP out to a file first; you can stream it to PHP.
You need execute the PHP page to serve the page it generates.
The easiest thing for you to do would be to add CGI support to your webserver in some basic form. This is non-trivial, but not too difficult. Basically you need to pass PHP an environment and input, and retrieve the output.
Once you have CGI support you can just use any executable, including PHP, to generate webpages.