$ controller-> referer(),local = true

时间:2013-09-13 13:06:34

标签: php cakephp

我有这个简单的代码

debug($this->referer('foo', true));
debug($this->referer('foo', false));

当我来自本地地址时,我希望得到相同的结果,即

'http://example.com/index.php/admin/groups'
'http://example.com/index.php/admin/groups'

相反,我得到了这个:

'http://example.com/index.php/admin/users/foo'
'http://example.com/index.php/admin/groups'

正如你可以看到我将local设置为true cakePHP referer()返回默认地址,即使referer在本地服务器中

我正在使用cakePHP 2.4

1 个答案:

答案 0 :(得分:0)

通常情况下,index.php不应显示在网址中,除非你有apache的mod_rewrite和规则已停用(或相当于其他http服务器),并启用了Cake内置的pretty URL's

根据代码库$this->referer(),在/的以下情况下会返回$local = true

  1. env('HTTP_REFERER')为空 AND 您尚未在App.fullBaseUrl中配置core.php
  2. 您的env('HTTP_REFERER')并非始于App.fullBaseUrl . $this->webroot(即www.example.com/index.php)。
  3. 如果设置了env('HTTP_X_FORWARDED_HOST'),它会替换上面env('HTTP_REFERER')的引用。

    从这两种选择来看,我会把钱放在App.fullBaseUrl没有被定义上:)

相关问题