dongquelu1239 2013-06-25 04:15
浏览 57
已采纳

如何在数据库中保存php代码[关闭]

Currently I am working on a project in which I have to save some PHP code in database, I am saving the code with PHP tags.

But I am not getting how I can retrieve the code exactly as stored into database.

I have tried the following methods :

a) Direct retrieval : When I am retrieving the databse directly then the value of $row['code'] is blank

b) using eval() : When I am using eval() then I am getting syntax error :

syntax error, unexpected '<' in H:\xampp\htdocs\trycodeonline\testing.php(27) : eval()'d code on line 1

c) using eval() without php tags : when I am removing the php codes then I am getting result instead of code, like I want to print echo "hello" but it is printing "hello"

So how can I print the php code ?

  • 写回答

4条回答 默认 最新

  • dongyi2993 2013-06-25 04:49
    关注

    If you really want to do it, you can use eval() as your method c) suggests:

    $var // your variable with the data from the DB
    <?php echo eval("?>". $var ."<?") ?>
    

    There are many legitimate use-cases where you'll want to store PHP commands in a database, and I personally find shouting "dont do it" without knowing the circumstances a bit unhelpful.

    Anyway, as has already been pointed out in various threads, there are security issues and other pitfalls using this approach and I would recommend against it. It will make debugging harder, and increases potential security vulnerabilities, and so on...

    Read this post and this post to know more about the pitfalls of using eval().

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度