note 104268 added to function.eval

From: Date: Sat, 04 Jun 2011 19:44:07 +0000
Subject: note 104268 added to function.eval
Groups: php.notes 
Request: Send a blank email to php-notes+get-180260@lists.php.net to get a copy of this message
When you want the user provide a formula to interpret, eval function is dangerous to use. A malicious user can type PHP code that may do harm when executed. To overcome this security problem with eval, it is sometimes better to parse a simple mathematical expression using PHP without relying on eval function. To achieve this there is a Math Parser for PHP here: http://www.bestcode.com/html/math_parser_for_php.html bcParserPHP can parse and evaluate expressions given at runtime without using eval() PHP function for security reasons. You can have user defined functions, variables in the expressions. It supports string literals and some boolean logic in the expression as well. Here is sample code: $parser = new MathParser(); $parser->setExpression($expr); $parser->setVariable('X', 5); echo 'Result=' . $parser->getValue(); Mete ---- Server IP: 69.147.83.197 Probable Submitter: 70.143.72.14 ---- Manual Page -- http://www.php.net/manual/en/function.eval.php Edit -- https://master.php.net/note/edit/104268 Del: integrated -- https://master.php.net/note/delete/104268/integrated Del: useless -- https://master.php.net/note/delete/104268/useless Del: bad code -- https://master.php.net/note/delete/104268/bad+code Del: spam -- https://master.php.net/note/delete/104268/spam Del: non-english -- https://master.php.net/note/delete/104268/non-english Del: in docs -- https://master.php.net/note/delete/104268/in+docs Del: other reasons-- https://master.php.net/note/delete/104268 Reject -- https://master.php.net/note/reject/104268 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#180260) next »