L
L
LittleFatNinja2015-08-15 19:24:29
PHP
LittleFatNinja, 2015-08-15 19:24:29

How to implement the launch of PHP code from PHP and what to do if functions like system () are disabled on the hosting (you need to compile cpp)?

1)
I'm building a website in PHP + Yii2 ( weblike.zz.mu )
Each user has a list of tasks (C++), he solves some problem and enters the code.
Accordingly, you need to compile its code.
Site on free hosting. Functions like system() are disabled. As I understand it, only buying a VPS will save me, since there is freedom of action, right?
2)
The same site, but tasks in php.
If it is clear with C++ - write it to a file, compile it, run it, then it is not very clear with PHP.
How can we sanely execute PHP code that came from the user? Already asked this, but I'll ask again. Last time they advised eval (), as I understand it, is this the only option?
You need to execute the php code in the line
$code = '<?php echo 5;'
I will be grateful for the answers.

Answer the question

In order to leave comments, you need to log in

6 answer(s)
N
Nazar Mokrinsky, 2015-08-15
@nazarpc

I would recommend taking a dedicated server (virtual or physical), put Docker there, and run the code EXCLUSIVELY in a one-time clean isolated environment with reasonable timeouts and resource limits.

T
TyzhSysAdmin, 2015-08-15
@POS_troi

If the hoster is a viable and normally configured server, then figs they will allow you to create such mego garbage, of course there are bypasses, but it depends heavily on the specific system, libraries and many more factors. And certainly not for the public such infa;) Do you
want ruffles and courtesans? Welcome to a dedicated VPS :)
Do what you want there, within the terms of the user agreement of course.

X
xmoonlight, 2015-08-15
@xmoonlight

If the site has SSH access and is allowed to compile (run) - connect with a local "loop" via sockets and issue commands from PHP.
Otherwise VPS only!

V
v- death, 2015-08-15
@vGrabko99

PHP is very simple (although quite dangerous) to write a file and then access it with Ajax

A
Alexander Taratin, 2015-08-15
@Taraflex

bellard.org/jslinux
You can compile and run directly on the client, but it will take a very long time.

D
Dmitry Marinin, 2015-08-15
@Creamov

Have a look at Runkit_Sandbox .

An instance of the Runkit_Sandbox class creates a separate thread of the main process with its own environment and allocated memory area (stack). Using additional constructor parameters, you can restrict the functionality of the interpreter in the sandbox, thus creating a safe environment for executing user code.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question