I would like to use PHP in Chrome extensions. I've tried to change background.html to background.php but that doesn't work. How can I do this?
You can't do this. PHP is a server-side language. This would require all your users to install a PHP interpreter, which is not feasible. Perhaps if you used Native Client you would be able to bundle PHP somehow, but that most likely wouldn't be worth it at all.
Related
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.
I'm looking to create a Google Extension for Chrome. I was wondering if it is possible to include a PHP file in the extension. After reading about extensions on Google's developer portal, they only mentioned HTML, CSS, and JavaScript. Nevertheless, is it possible to use PHP in the extension? Help is greatly appreciated.
No. PHP only runs on the server, while the extensions run in the browser. You can, of course, contact your server, but you can't run PHP inside the browser.
No. Well, you can include a PHP file, but it won't be processed because PHP is run on a server. You can make a function in Javascript to contact a PHP script on your server, however.
The google extensions only support HTML, CSS and Javascript files and
this is what is considered a client, while PHP is a server-side
language.
You can find more about Google Extensions here
https://developer.chrome.com/docs/extensions/mv3/architecture-overview/
I'm trying to write a website in PHP that allows the user to enter PHP code, and then be able to run it on my server. However, I want to be able to disable certain features (file access, database access, etc.). Basically, I want the code to run without any risk to my server, and if the code does attempt to do something dangerous, I just want the code to stop running (I don't mind if it just stops, produces an error, or carries on while ignoring the dangerous code).
Is this possible, and if so, how could I achieve this?
Thanks :)
It is possible using libraries that do some simple checking or limiting.
Take a look at a PECL (PHP Extensions) extension called RunKit_Sandbox http://php.net/manual/en/runkit.sandbox.php or PHPSandbox.
The key to look for on Google is PHP Sandbox, it will find you similar libraries.
vi php.ini
and then find disable_functions,
disable the functions as you want! like this :
disable_functions = exec,passthru,popen,proc_open,shell_exec,system,phpinfo,assert,chroot,getcwd,scandir,delete,rmdir,rename,chgrp,chmod,chown,copy,mkdir,file,file_get_contents,fputs,fwrite,dir
I actually developed a package specifically for these kinds of use cases. It can be fully configured and even used to override dangerous functions and globals.
https://github.com/fieryprophet/php-sandbox
I am writing a Chrome extension which sends some data to a PHP file, which then the PHP file sends it to a database.
All is fine and well, but I just wanted to ask if my users need to have PHP as well as a server installed on their machines, for the extension to work?
According to some posts it does (for example). But if this indeed the case, then how can an extension interact with a database without forcing the users to install a server and PHP.
Thanks in advance.
php is a server side scripting language, meaning that all of the processing is done on your server. there is no reason that any user would need to install anything in able to access a php application.
You might want to look into WebSQL (http://en.wikipedia.org/wiki/Web_SQL_Database).
It's not developed anymore (and stays unfinished), but according to this Wikipedia article it's based on SQLite and chrome supports is.
You can interact with a database (IndexedDB) using JS in your extension.
Resources:
Can I use...
IndexedDB | MDN
Since you are making a Chrome extension, there may not be any concern for cross-browser support, but according to HTML5 Please, a polyfill is recommended.
I am running PHP version 5.1.6 currently, but I would have an application which makes pretty heavy use of the json_encode and json_decode functions, as such, I would like to add these functions to my server's install of PHP (as these functions only ship with PHP versions PHP 5.2 +)
What is the best way of doing this. I'm not too down with the whole Terminal approach so if there was another way that would be great
Many thanks in advance
If you're unable to upgrade, use PEAR's Services_JSON. It works as of PHP 4.3 so you should be fine.
Maybe you should put somewhere in the root of your application a call to a checker function that does function_exists() for a couple of your needed function and if not stops the execution to prevent unwanted results.