PHP eval issue with PHP + HTML code

天涯浪子 提交于 2019-11-29 15:37:45

I would guess that you're trying to eval() something that contains an opening <?php tag. And that leads to the error at hand.

Best advice - never store php and html code in your database. And avoid eval() like the plague.

I can't really tell what's wrong with your code, as you haven't provided enough information. But even if I did have some advice, I don't think I could give it in good conscience.

You should redesign your whole application so that it doesn't require storing such things in the database. I can't imagine why it would be necessary.

Vishal

just right der...........

eval('?>' . $content .'<?php');
intuited

You need to re-open php mode after the EVALED. Apparently you have to do this with <? rather than the full <?php.

As a rule eval is to be avoided. But rules are made to be broken. There's a thread at When is eval evil in php? that gives some less dogmatic advice.

Depending on what you want to do, it might be suitable to use a template file that you source, with text that will vary stored in a local variable prior to sourcing the template.

As for storing code to be executed in the DB... this does happen in some frameworks like Drupal to provide convenient extensibility, but then Drupal is pretty thoroughly scoured for security weaknesses.

Also if you're writing self-modifying code then you need to use eval(). Not sure if anyone has done that in php but it would certainly be interesting.

$contents = htmlentities($contents);
echo html_entity_decode(eval($contents));
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!