Re: How to parse PHP tags in a string?

From: Date: Wed, 07 Feb 2007 17:39:46 +0000
Subject: Re: How to parse PHP tags in a string?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-248504@lists.php.net to get a copy of this message
Zak Mc Kracken wrote: > Hi all, > > Is there a PHP function that parses a string as it was the content of a > PHP file? > > I have a CMS application and editors write the news items text into a > text area. Since they have some knowledge of PHP, I'd like to allow them > to insert <? ... ?> or <?= ... ?> and have the content blocks parsed and > executed. OK, this could be easily done parsing the string and passing > the block contents to eval(). However I wonder wether there is some > function already doing that (maybe in a more efficient way). > > Thanks a lot in advance. Hi, This is a very dangerous thing to do, as it will allow execution of arbitrary PHP code. I highly recommend that you not allow this. Instead, some kind of plugin system could be allowed where editors can specify a plugin (something like [plugin name="blah" param1="blah" param2="halb"]) and they upload the PHP code to a file on the server, register that file as the plugin "blah" and go from there. Anything else is begging to get the site hacked and cause yet another vulnerability in a php app. Greg

« previous php.general (#248504) next »