如何使用 PHP 获取以前的 url
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4662110/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get the previous url using PHP
提问by Nawaz
Suppose my site's url is given as hyperlink on some page on the internet; that page could be anything on internet - blog, orkut, yahoo, even stackoverflow etc, and someone clicks on it,and visited my site. So can we know, using php, the previous url from which the visitor came to my page?
假设我网站的 url 在互联网上的某个页面上以超链接的形式给出;该页面可以是 Internet 上的任何内容 - 博客、orkut、雅虎,甚至是 stackoverflow 等,有人点击它并访问了我的网站。那么我们可以使用 php 知道访问者访问我的页面的前一个 url 吗?
回答by BoltClock
Use the $_SERVER['HTTP_REFERER']
header, but bear in mind anybody can spoof it at anytime regardless of whether they clicked on a link.
使用$_SERVER['HTTP_REFERER']
标题,但请记住,任何人都可以随时欺骗它,无论他们是否点击了链接。
回答by Andreyco
$_SERVER['HTTP_REFERER']
is the answer
$_SERVER['HTTP_REFERER']
是答案
回答by TenTen Peter
$_SERVER['HTTP_REFERER']
will give you incomplete url.
$_SERVER['HTTP_REFERER']
会给你不完整的网址。
If you want http://bawse.3owl.com/jayz__magna_carta_holy_grail.php
, $_SERVER['HTTP_REFERER']
will give you http://bawse.3owl.com/
only.
如果你想要http://bawse.3owl.com/jayz__magna_carta_holy_grail.php
,$_SERVER['HTTP_REFERER']
只会给你http://bawse.3owl.com/
。
回答by Nick DuBois
I can't add a comment yet, so I wanted to share that HTTP_REFERER is not always sent.
我还不能添加评论,所以我想分享 HTTP_REFERER 并不总是发送。
回答by Kristóf Bella
But you could make an own link for every from url.
但是您可以为每个来自 url 的链接创建自己的链接。
Example: http://example.com?auth=holasite
示例:http: //example.com?auth=holasite
In this example your site is: example.com
在此示例中,您的站点是:example.com
If somebody open that link it's give you the holasite value for the auth variable.
如果有人打开该链接,它会为您提供 auth 变量的 Holasite 值。
Then just $_GET['auth'] and you have the variable. But you should have a database to store it, and to authorize.
然后只需 $_GET['auth'] 并且您拥有变量。但是您应该有一个数据库来存储它并进行授权。
Like: $holasite = http://holasite.com(You could use mysql too..)
如:$holasite = http://holasite.com(你也可以使用 mysql..)
And just match it, and you have the url.
只需匹配它,您就拥有了网址。
This method is a little bit more complicated, but it works. This method is good for a referral system authentication. But where is the site name, you should write an id, and works with that id.
这种方法稍微复杂一点,但它有效。此方法适用于推荐系统身份验证。但是站点名称在哪里,您应该写一个ID,并使用该ID。