Kohana 3.2 - 获取引荐来源网址

发布于 2024-12-03 22:14:20 字数 410 浏览 1 评论 0原文

我正在尝试使用以下代码获取 Kohana 3.2 中的引用 URI:

$referrer = $this->request->referrer();
var_dump($referrer);

但是该函数返回 NULL,我希望它返回我离开以访问此页面的页面。

这是它应该如何工作的......如果是这样,我错过了什么或做错了什么?

这是在控制器中运行的。

此处的文档: http://kohanaframework.org/3.2/guide/api/Request#referrer< /a>

I'm attempting to get the referrer URI in Kohana 3.2 using the following code:

$referrer = $this->request->referrer();
var_dump($referrer);

However the function returns NULL, I'm expecting it to return the page I left to get to this one.

Is that how it should work... and if so what am I missing or doing wrong?

This is being run in the Controller.

Documentation here: http://kohanaframework.org/3.2/guide/api/Request#referrer

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

大海や 2024-12-10 22:14:21

我遇到的问题是由我的 Kohana 系统设置方式引起的。基本上我的系统中间有一个routeHandler,它控制用户采用的路线。在该脚本中,生成并执行了一个新请求。

发生的情况是在创建新的请求对象时,没有添加引用者 uri。我添加了以下代码,现在我可以在路由过程结束时从控制器获取引用 uri。

$referrer = $this->request->referrer();
$request = new Request($uri);
$request->referrer($referrer);

echo $request->execute()
             ->send_headers()
             ->body();

或者,atma 建议的更干净、更原生的解决方案如下:

Request::initial()->referrer()

The issue I was having was cause by the way my Kohana system is setup. Basically I have a routeHandler in the middle of my system which controls the routes users take. In that script a new request was generated and then executed.

What was happening was when creating the new request object it wasn't having the referrer uri added to it. I have added the following code and now I am able to get the referring uri from the controller at the end of the routing process.

$referrer = $this->request->referrer();
$request = new Request($uri);
$request->referrer($referrer);

echo $request->execute()
             ->send_headers()
             ->body();

Alternatively a cleaner more native solution as suggested by atma is the following:

Request::initial()->referrer()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文