【发布时间】:2014-01-08 22:02:17
【问题描述】:
我遇到了一些起初对我来说似乎很简单但现在证明非常困难的问题。也许我想多了 - 很想得到你的帮助。
概述: 我有一个带有两个接口的 Web 应用程序(1 个用于 clients,1 个用于 customers)。所有 客户 都以一种方式路由,而所有 客户 都以另一种方式路由。我根据他们的子域确定要显示的登录屏幕。 customers 获取基本域 (+www),clients 转到 [clientName].example.com
问题: 我之前通过对 env("HTTP_HOST") 进行字符串操作来确定这一点——请参见下面的代码。但是,现在在使用本地 IP(用于与其他设备/人进行测试)时会出现问题。我的代码,它寻找“。”在主机环境中失败,因为 IP 有 3 个点,而 'localhost' 有 0
这些是我建立的不同命名参数以及我想要的路线...
CUSTOMER ----------------------------- CLIENT
xyz.example.com ------>
<------ www.example.com
<------ example.com
xyz.localhost ------>
<------ www.localhost
<------ localhost
xyz.192.168.X.X ------>
<------ www.192.168.X.X
<------ 192.168.X.X
我可能真的想太多了,我希望有一些简单的 PHP 函数,比如“get_subdomain()”,可以为我做这件事。但我没有看到它,真的很想得到一些帮助。
谢谢!
当前代码:
$host = env("HTTP_HOST");
$group = null;
// if there is exactly one dot IE example[dot]com then there is no subdomain
if(substr_count($host,'.')==1){
$group = 'customer'
}else{ // there is a subdomain
$subdomain = substr($host, 0, strpos($host, "."));
if($subdomain=='www'){
$group = 'customer'
}else{
$group = 'client'
}
}
CakePhp 是否有帮助?
【问题讨论】:
标签: php cakephp routing ip subdomain