Re: Re: Executing php code within a string
| From: | Chris Hobbs | Date: | Thu, 08 Nov 2001 20:57:38 +0000 |
| Subject: | Re: Re: Executing php code within a string | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-73949@lists.php.net to get a copy of this message | ||
Thanks to both you and Thargor. eval() is exactly what I was after, but your comments about security are well-taken - this certainly gives an almost blank check to anyone who can post to the site. I'll work on my own version of eval [string ch_eval (string to_be_evaluated) ;)] to try to address this concern.
Julio Nobrega Trabalhando wrote:
eval(); But you should be VERY careful, limiting what things they can put inside <?php ?>. It's easier to allow just some functions to run. Or, you could do somekind of an interpreter. Allow them to put things inside a special tag, and special commands. Say for example your opening tag is: <|CH Closing: |> Then you make available to them certain 'functions'. For example: <|CH current_date |> Would display the current date. It's more secure, and I mean MUCH more secure than using eval(); since you will have control of what appears inside <|CH |>, but a little workier to implemet. Or maybe I am reinventing the wheel on this.... -- Julio Nobrega A hora está chegando: http://toca.sourceforge.net "Chris Hobbs" <chobbs@silvervalley.k12.ca.us> wrote in message news:3BEAE760.5070604@silvervalley.k12.ca.us...-- _______ ___ _ ____ _____ Chris Hobbs / ____\ \ / / | | |/ ___\| __ \ Head Geek | (___ \ \ / /| | | | (___ | | | | WebMaster \___ \ \ \/ / | | | |\___ \| | | | PostMaster ____) | \ / | |__| |____) | |__| | \____/ \/ \____/ \____/|_____/ http://www.silvervalley.k12.ca.us chobbs@silvervalley.k12.ca.usI've a simple content management system which allows users to use full html within their submitted items. I then output the data by pulling the info out of a db and simply echo'ing it to the browser. Anyway, I'd like to make some php functionality available to them, so I would like them to be able to enter something like the following: <h2> The date is <? echo date("m-d-Y")?>.</h2> This would later be pulled out from the database and sent to the browseras:<h2> The date is 11-08-2001.</h2> Right now, of course, I simply echo the <? ... ?> and not the result. Any ideas on how to process the php component before I echo it? --_______ ___ _ ____ _____ Chris Hobbs / ____\ \ / / | | |/ ___\| __ \ Head Geek | (___ \ \ / /| | | | (___ | | | | WebMaster \___ \ \ \/ / | | | |\___ \| | | | PostMaster ____) | \ / | |__| |____) | |__| | \____/ \/ \____/ \____/|_____/ http://www.silvervalley.k12.ca.us chobbs@silvervalley.k12.ca.us