简体   繁体   English

重定向前使用php更改HTTP_REFERRER

[英]Change HTTP_REFERRER using php before redirecting

I have a script which redirects to an link like 我有一个脚本可以重定向到类似的链接

header("Location:http://foo.com/abc.xyz");

but I want to either set the HTTP_REFERRER to be http://foo.com or blank so that the site http://foo.com can not track that the reference was sent from another domain in which script is installed. 但是我想将HTTP_REFERRER设置为http://foo.comblank以便站点http://foo.com无法跟踪引用是从安装了脚本的另一个域发送的。

Well of course there is a way to spoof a referer. 当然,有一种欺骗引荐来源的方法。 How usefull it will be is something for you to decide :) 您可以决定这有多有用:)

Since the referer comes from the web browser client, we will need to create our own "PHP WWW Client"... Basically a proxy. 由于引荐来自网络浏览器客户端,因此我们需要创建自己的“ PHP WWW客户端” ...基本上是一个代理。

Here is some code that will spoof all the information that is there: 这是一些代码,它将欺骗所有存在的信息:

<?php

// Setup Information
$host = "www.yoursite.com";
$page = "/index.html";

// Open the socket
$fp = fsockopen($host,80,$errno,$errstr,30) or die("Could not establish a connection. $errstr($errno)");

// Request the page
fputs($fp,"GET $page HTTP/1.0\r\n");
fputs($fp,"User-agent: PHP WWW Client\r\n");
fputs($fp,"Referer: http://www.anothersite.net\r\n");
fputs($fp,"\r\n");

// Read response
while (!feof($fp)) {
$page .= fgets ($fp,128);
}

// Close Socket
fclose($fp);

?>

$page will now contain the HTML contents of the page you just recieved from the server. $page现在将包含您刚从服务器接收到的页面的HTML内容。

As for what you do with it next, that is up to you :) You will probably need to format any URLs in the code so they will work from your domain. 至于接下来要做什么,这取决于您:)您可能需要格式化代码中的所有URL,以便它们在您的域中起作用。 Then print out the html code. 然后打印出html代码。

Generally doing this is not really a good idea, but this is the only way that I know of to "spoof" the referer and user-agent. 通常,这样做并不是一个好主意,但这是我所知道的“欺骗”引用程序和用户代理的唯一方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM