How to execute PHP code entered from textbox or textarea
Posted on May 30, 2008
Filed Under how-to, php, tips and technique
Yesterday, Sujit asked me how can we execute the php code entered through textarea in PHP. In many cases, it’s not good to execute the php code entered from textarea in PHP from the secruity point of view but in some cases you may have to do this and I’m going to tell you here how you can do this in PHP.
Execute the PHP code entered through textbox or textarea
echo "echo 'test';"; //just prints echo 'test';
Above line just prints echo ‘test’; , you can’t do it from that way. For executing the php code entered form textarea, you have to take the help of useful PHP function called eval() . Take a look at few examples of eval() function to execute the PHP code which is supplied as a string.
eval("echo 'test';"); // prints test in browser
eval(" phpinfo(); "); //outputs the information provided by phpinfo()
Isn’t that easy to do? eval() comes handy when you’ve to execute the PHP code which is supplied as a string . But always be careful, 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.
Popularity: 8% [?]
Follow me on twitter at http://twitter.com/roshanbh.
Related Posts
» How to make rounded corner textbox using css
» Changing textbox value from dropdown list using Ajax and PHP
» Textbox to accept only numbers (digits) using jquery
» Prevent form post request from another domain in PHP
Comments
One Response to “How to execute PHP code entered from textbox or textarea”
Leave a Reply






[...] Read More: http://roshanbh.com.np/2008/05/execute-php-code-textbox-textarea.html [...]