admin管理员组文章数量:1313598
I try to load a random page which I set in my URL, into an iframe. Let's say I try to load "" 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=
Only a blank page is loaded. I know the reason for this is that Google is sending an "X-Frame-Options: SAMEORIGIN" response header.
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?
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
Only a blank page is loaded. I know the reason for this is that Google is sending an "X-Frame-Options: SAMEORIGIN" response header.
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?
Share Improve this question edited Nov 12, 2020 at 9:04 Black asked Sep 10, 2015 at 9:19 BlackBlack 20.4k46 gold badges185 silver badges296 bronze badges 8-
You may want to use a modern way instead of using
<iframe>
– Raptor Commented Sep 10, 2015 at 9:23 - Can you tell me more? Where can i learn a better way? – Black Commented Sep 10, 2015 at 9:25
- PHP proxy is a way, just JS proxy like XHook is another way – Raptor Commented Sep 10, 2015 at 10:00
-
You were talking about that
<iframe>
is obsolete, so what is the modern alternative? – Black Commented Sep 10, 2015 at 10:48 - iframe of course is fading out. – Raptor Commented Sep 10, 2015 at 11:15
1 Answer
Reset to default 5Use this script unment the proxy lines if you are behind any proxy server and want to bypass it using the authentication the proxy url, domain, username, password.
I used header("Access-Control-Allow-Origin: *");
Since I was calling this script from a different domain.
File: proxyscript.php
<?php
header("Access-Control-Allow-Origin: *");
echo get_page($_GET['url']);
//echo get_page("http://www.google.");
function get_page($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
/*
$proxy = 'http://proxy.pany.: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;
}
?>
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.')">Google</button>
<iframe id="frame" src=""></iframe>
</body>
</html>
本文标签: javascriptHow to use a php proxy to load a site into a iframeStack Overflow
版权声明:本文标题:javascript - How to use a php proxy to load a site into a iframe? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741938793a2406018.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论