How can I find an application's base url?

后端 未结 11 1394
南方客
南方客 2020-12-16 01:35

I\'d like to find the base url of my application, so I can automatically reference other files in my application tree...

So given a file config.php in the base of my

11条回答
  •  自闭症患者
    2020-12-16 01:52

    You can find the base url with the folowing code:

    define('SITE_BASE_PATH','http://'.preg_replace('/[^a-zA-Z0-9]/i','',$_SERVER['HTTP_HOST']).'/'.str_replace('\\','/',substr(dirname(__FILE__),strlen($_SERVER['DOCUMENT_ROOT']))).'/');
    

    Short and best.

提交回复
热议问题