如何使用PHP代理在iframe中打开谷歌? [英] How to use a php proxy to open google in an iframe?

查看:483
本文介绍了如何使用PHP代理在iframe中打开谷歌?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将我在网址中设置的随机页面加载到iframe中。假设我尝试在iframe中加载 https://www.google.de

I try to load a random page which I set in my URL, into an iframe. Let's say I try to load "https://www.google.de" in an iframe.

<iframe src="<?php echo $_GET['URL'];?>" width="600" height="500"></iframe>

这是我设置网址的方式:

This is how I set the URL:

localhost/test/index.php?URL=https://www.google.de

仅加载空白页面。我知道这样做的原因是Google正在发送一个X-Frame-Options:SAMEORIGIN响应标题。

Only a blank page is loaded. I know the reason for this is that Google is sending an "X-Frame-Options: SAMEORIGIN" response header.

但是,我试图找到一种方法来加载它无论如何,有人告诉我使用PHP代理脚本执行此操作,但我进行了研究,发现没有任何帮助。

However, I try to find a way to load it anyway, someone told me to use a PHP Proxy script to do this, but I researched and found nothing helpful yet.

我该如何解决这个问题?

How can I solve this?

推荐答案

如果您位于任何代理服务器后面并且想要使用代理URL,域,用户名,身份验证绕过它,请使用此脚本取消注释代理行密码。

Use this script uncomment the proxy lines if you are behind any proxy server and want to bypass it using the authentication the proxy url, domain, username, password.

我用标题(Access-Control-Allow-Origin:*); 因为我是从另一个域调用此脚本。

I used header("Access-Control-Allow-Origin: *"); Since I was calling this script from a different domain.

<?php
    header("Access-Control-Allow-Origin: *");

    echo get_page($_GET['url']);
    //echo get_page("http://www.google.com");
    function get_page($url){
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,$url);
        /*
        $proxy = 'http://proxy.company.com:8080';
        $proxyauth = 'domain\proxy_username:proxy_password';
        curl_setopt($ch, CURLOPT_PROXY, $proxy);
        curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth);
        */
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        $data = curl_exec($ch);
        curl_close($ch);
        return $data;
    }
?>



文件:index.html



File: index.html

<html>
    <head>
        <script>
            function getURL(url){
                document.getElementById('frame').src 
                   = 'path/to/proxyscript.php?url='+encodeURIComponent(url);
            }
        </script>
    </head>
    <body>
        <button onclick="getURL( 'http://www.google.com')">Google</button>
        <iframe id="frame" src=""></iframe>
    </body>
</html> 

这篇关于如何使用PHP代理在iframe中打开谷歌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆