PHP - Referer перенаправляют сценарий

Может быть, Atom Html Previewer предназначен просто для того, чтобы иметь представление о том, как выглядит Html, и не включает в себя все функции браузера. Отказ в доступе к ресурсам через кросс-источник - это ограничение вашего интернет-браузера. Сервер сообщает вашему браузеру, что ваш скрипт пытается извлечь ресурс из другого домена, и это браузер блокирует доступ. Это ограничение не существует, например, если вы разрабатываете сценарий Powershell или консольное приложение C #, поскольку они работают в Windows, тогда как ваш код Javascript использует браузер в качестве платформы и, следовательно, на него распространяются его ограничения.

10
задан 13 May 2009 в 14:40
поделиться

3 ответа

эта функция должна дать вам отправную точку он получит любой URL-адрес http с указанным реферером

, обработка параметров запроса должна быть довольно тривиальной, поэтому я оставлю эту часть для вас

<?php

    echo geturl('http://some-url', 'http://referring-url');

    function geturl($url, $referer) { 

        $headers[] = 'Accept: image/gif, image/x-bitmap, image/jpeg, image/pjpeg,text/html,application/xhtml+xml'; 
        $headers[] = 'Connection: Keep-Alive'; 
        $headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8'; 
        $useragent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0)'; 

        $process = curl_init($url); 
        curl_setopt($process, CURLOPT_HTTPHEADER, $headers); 
        curl_setopt($process, CURLOPT_HEADER, 0); 
        curl_setopt($process, CURLOPT_USERAGENT, $useragent);
        curl_setopt($process, CURLOPT_REFERER, $referer);
        curl_setopt($process, CURLOPT_TIMEOUT, 30); 
        curl_setopt($process, CURLOPT_RETURNTRANSFER, 1); 
        curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1); 

        $return = curl_exec($process); 
        curl_close($process); 

        return $return; 
    } 

?>
12
ответ дан 3 December 2019 в 23:14
поделиться

You can use one of the services available on Internet which allow hiding referrers (by setting their address), but you cannot impose a specific referrer that ain't the actual referrer. The user must actually be redirected to that website (which will appear as a referrer) before he is redirected to the target website.

One of such services: http://linkanon.com

edit:

Since you changed your question now, my comment about writing a user agent in PHP which acts like a proxy, applies, but then this gets close to a criminal activity, because you will be displaying a third party website to a user who might think that she is in the actual website, while in fact she will have loaded your content (the content you have passed on). To perform this close-to-criminal activity (you are one step away from trying to read a username and password), you load the third party's website content with PHP by using your own written user agent which specifies the fake referrer and simply passes the output to visitor of your website. The function in PHP which lets one send HTTP headers, is header($header):

header("Referer: http://example.org");

Instead of shouting at people who try to help, you could try to read HTTP (that's the protocol according to which the world turns around) specification regarding Referer header: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html (See Section 14.36).

You also might want to read http://en.wikipedia.org/wiki/Referrer_spoofing where you can see that it's all about client side. PHP is server side. All you can do is try to write a client code (Javascript) generated by PHP, but if you have any luck, then you're breaking into user's world.

2
ответ дан 3 December 2019 в 23:14
поделиться

The referer is set by your browser, not by any server side mechanism. You could, I guess, construct a proxy in PHP that makes the request of the remote server and sets the referer header appropriately. It seems more useful to just use a Firefox plugin, e.g. http://www.stardrifter.org/refcontrol/.

Edit: I'd reword your question to make it clear you want to write a PHP proxy, with a custom referrer header. I'd probably just modify something like http://sourceforge.net/projects/poxy/ to take the referrer parameter and pass it on.

Edit again: You may be clear on what you're asking, but asking for the impossible doesn't make it possible. The browser is responsible for setting the referrer header; it uses the URI that caused it to redirect to a new resource. You're asking for a script that says "Please visit http://example.net, but pretend that I'm actually www.foo.com when you do so". There is no mechanism for the server to instruct the browser to "lie" about where it came from.

I suppose it may be possible via some convoluted JavaScript hacking, but it would be hacking in the black hat sense - a web site being able to force a browser to spoof the referrer would be a real security hole.

0
ответ дан 3 December 2019 в 23:14
поделиться
Другие вопросы по тегам:

Похожие вопросы: