public function referer($default = null, $local = false) { if ($ref = $this->env('HTTP_REFERER')) { if (!$local) { return $ref; } $url = parse_url($ref) + array('path' => ''); if (empty($url['host']) || $url['host'] === $this->env('HTTP_HOST')) { $ref = $url['path']; if (!empty($url['query'])) { $ref .= '?' . $url['query']; } if (!empty($url['fragment'])) { $ref .= '#' . $url['fragment']; } return $ref; } } return $default !== null ? $default : '/'; }
public function testRefererLocalFromNotLocal() { $_SERVER['HTTP_REFERER'] = 'http://lithium.com/posts/index'; $request = new Request(); $expected = '/'; $result = $request->referer('/', true); $this->assertEqual($expected, $result); }