doutuo7126 2012-07-15 17:12
浏览 24
已采纳

包括php on file request

I would honestly be surprised if anything like this exists, but I couldn't find anything relevant with my Google-fu.

I'm including a PHP file using require_once() on every page of my site. The file is a light custom-made framework.

I was wondering if I could drop the entire require_once() line and, by using another obscure mechanism, include the library at the beginning of every file in a specified folder.

The reason behind this is that the files in that particular folder are going to be modified by people with limited coding knowledge and I don't want them screwing up the PHP lines thinking they're not important.

EDIT: The library will be ultimately distributed and aims to work on typical PHP installatons.

Thanks!

  • 写回答

2条回答 默认 最新

  • dsh7551 2012-07-15 17:17
    关注

    Another technique that I feel is less obscure than auto_prepend_file would be to have all requests to this folder first redirected to one file, that then loads the library, and then loads the file you're going to have these other users modifying.

    Here's how I've parsed this sort of thing using your rewrite code... If the htaccess file is in the same directory as the folder, I think the rewrite rule will look like this: RewriteRule ^(.*)$ index.php/$1 [L]

    In the index.php file I usually load some sort of configuration for the site, followed by delegating. I use this function right here to get the current url... I'm not entirely sure if it's overkill or not, but it's worked consistently for me across several platforms.

    function get_current_url() {
     $pageUrl = 'http';
     if (@$_SERVER["HTTPS"] == "on") {$pageUrl .= "s";}
     $pageUrl .= "://";
     if ($_SERVER["SERVER_PORT"] != "80") {
      $pageUrl .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
     } else {
      $pageUrl .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
     }
    
     return $pageUrl;
    }
    

    Then you can essentially parse the result of get_current_url() using php's parse_url() function and delegating appropriately.

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

报告相同问题?

悬赏问题

  • ¥15 制裁名单20240508芯片厂商
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致