You are here: Re: how to run php code within string? « PHP Programming Language « IT news, forums, messages
Re: how to run php code within string?

Posted by Justin Koivisto on 11/19/69 11:47

Erwin Moller wrote:
> Justin Koivisto wrote:
>
>> I just used eval for the first time yesterday....
>>
>> <?php
>> foreach($scoring as $page=>$words){
>> $evalstatemnet=array();
>> foreach($parts as $word){
>> $evalstatemnet[]='isset($words[\''.$word.'\'])';
>> }
>> if(!(eval(join(' && ',$evalstatemnet)))){
>> unset($scoring[$page]);
>> }
>> }
>> ?>
>>
>> Part of a search function where $word would only ever be [a-z0-9_] -
>> Even then, I wasn't sure if I really wanted to use it... A few hours
>> later, it was replaced by something else (different algo). ;)
>
> I do not see how that piece of code makes sure that no naughty commands are
> executed.
> It completely depends on what $scoring contains.
> If you let me deliver that $scoring-array, I think I can delete the content
> of your harddrive.
> But maybe I miss something completely. :-/

See above.. the stuff that was used in the eval statement could only
contain letters a-z (lowercase only), digits 0-9, and the underscore.
Then they were single quoted, so the eval statement would look something
like:

isset($words['testing']) && isset($words['12_435']) &&
isset($words['id_17'])

The $scoring array been constructed in the function, and if there was
found to be any characters other than specified above, the function
would have returned FALSE long before it reached that loop.

--
Justin Koivisto, ZCE - justin@koivi.com
http://koivi.com

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация