Validate user inputted PHP code before passing it to eval()

前端 未结 5 1209
傲寒
傲寒 2021-01-12 10:10

Before passing a string to eval() I would like to make sure the syntax is correct and allow:

  1. Two functions: a() and b()
  2. Four operators: /*-+
5条回答
  •  庸人自扰
    2021-01-12 10:32

    hakre's answer, using regexes is a nice solution, but is a wee bit complicated. Also handling a whitelist of functions becomes rather messy. And if this does go wrong it could have a very nasty effect on your system.

    Is there a reason you don't use the javascript 'eval' instead?

提交回复
热议问题