doufutao4428 2014-07-18 07:46
浏览 30

从子目录Index.php Codeigniter爆炸URL路径

I am having trouble getting the main url from my sub directory. It has it's own application folder and index.php

http://localhost/project/admin/

I need my function below some how to remove admin/ and only display http://localhost/project/

How am I able to explode it or something similar that will remove admin/ and just show parent url.

http://localhost/project/

if (isset($_SERVER['HTTP_HOST'])) {

    $catalog_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https' : 'http';
    $catalog_url .= '://'. explode('/' . $catalog_url);
    $catalog_url .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);

} 
else{
    // Back Up Url
    $base_url = 'http://localhost/';
}

define('CATALOG_URL', $catalog_url);

unset($catalog_url);
  • 写回答

1条回答 默认 最新

  • douchenbiao0916 2014-07-18 09:35
    关注

    After thinking about it for a while I had to do this

    if (isset($_SERVER['HTTP_HOST'])) {
    
        $catalog_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https' : 'http';    
        $catalog_url .= '://'. $_SERVER['HTTP_HOST'] . rtrim(rtrim(dirname($_SERVER['SCRIPT_NAME']), 'admin'), '/.\\'). '/';
    
        } else {
    
        // Back Up Url
        $base_url = 'http://localhost/';
    
    }
    
    define('CATALOG_URL', $catalog_url);
    
    unset($catalog_url);
    
    评论

报告相同问题?

悬赏问题

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