Is this possible to execute PHP code entered from textbox or textarea?

Today, I am going to write “can we execute the php code entered through textarea in PHP?” 

If yes than How?

Some of my friends asked me how can we execute the php code entered through text area or textbox in PHP.

Let me tell you one thing before proceeding In most cases, it’s not right way to execute the php code entered from textarea or textbox in PHP for the security point of view but in some cases you may have to do this and I am going to tell you the way “how you can do this in PHP”.

Execute the PHP code entered through textbox or textarea :-

 echo "echo ''test''”;

It will print echo ”test”;

As you can see above line just prints echo test , you can not do it directly from that way. We need to use PHP Function for execute the PHP code entered form textarea or textbox,  that PHP function is  called eval() .

Now you can take a look at few examples of eval() function to execute the PHP code which is supplied as a string.

 

 eval("echo ''test'';"); 

It will prints test in browser

 eval(" phpinfo(); "); 

Ones again I want to tell you that be careful while using eval() function as there are a lot of dangerous things can be done if PHP code can be executed from eval() to invade the security of your website is not that easy to do eval() comes handy when you have to execute the PHP code which is supplied as a string .

 

Leave a Reply

Your email address will not be published. Required fields are marked *

one × three =