Php 如果机架未正确加载
我正在iframe中加载一个页面。这是我正在使用的代码: 文件:iframe\u load.htmlPhp 如果机架未正确加载,php,html,iframe,Php,Html,Iframe,我正在iframe中加载一个页面。这是我正在使用的代码: 文件:iframe\u load.html <?php echo 'URL = '.$_REQUEST['url']; ?> <iframe width="1015px" id="article_frame" src="<?php echo $_REQUEST['url']; ?>" style="border:0 none;" height="576px" sandbox="allow-scripts"&
<?php echo 'URL = '.$_REQUEST['url']; ?>
<iframe width="1015px" id="article_frame" src="<?php echo $_REQUEST['url']; ?>" style="border:0 none;" height="576px" sandbox="allow-scripts"></iframe>
<?php
// create a variable with the URL
// this is the normal URL, we will encode it later, when we echo it.
$other_websites_url = 'http://theirsite.com/index.php?key1=val1&key2=val2';
?>
<a href="http://yoursite.com/iframe_load.html?url=<?php echo urlencode($other_websites_url); ?>">Click to go to iframe_load.html</a>
<?php // ^ see, here we urlencode the URL, just before we paste it inside our own URL.
您必须对url参数进行编码。请尝试以下URL:
为了便于演示,让我简化该URL:
http://yoursite.com/iframe_load.html?url=http://theirsite.com/index.php?a=1&b=2
请注意,他们网站的URL也包含一个查询字符串(index.php?a=1&b=2
)。因为URL包含&
,所以PHP就是这样拆分字符串的:
url=http://theirsite.com/index.php?a=1
&
b=2
正如您所看到的,url
现在只保存url的一部分,而不是完整的url(因为它被和分割)
&
符号过早地“破坏”了URL,因此您必须将其替换为不会破坏URL的内容
必须向iframe\u load.html传递一个编码的URL,以防止PHP错误解释URL:
http://yoursite.com/iframe_load.html?url=http%3A%2F%2Ftheirsite.com%2Findex.php%3Fkey1%3Dval1%26key2%3Dval2
(请参见iframe\u load.html?url=
之后的部分不再包含任何?
或&
)
如果您从另一个页面链接到iframe_load.html,您可以使用PHP的函数为您执行以下操作:
一些链接到iframe\u load.html的页面
<?php echo 'URL = '.$_REQUEST['url']; ?>
<iframe width="1015px" id="article_frame" src="<?php echo $_REQUEST['url']; ?>" style="border:0 none;" height="576px" sandbox="allow-scripts"></iframe>
<?php
// create a variable with the URL
// this is the normal URL, we will encode it later, when we echo it.
$other_websites_url = 'http://theirsite.com/index.php?key1=val1&key2=val2';
?>
<a href="http://yoursite.com/iframe_load.html?url=<?php echo urlencode($other_websites_url); ?>">Click to go to iframe_load.html</a>
<?php // ^ see, here we urlencode the URL, just before we paste it inside our own URL.
请按以下步骤操作:
$datum = parse_url($_SERVER['REQUEST_URI']); /*use this if you want to get current page path*/
$test = "http://mywebsite.com/iframe_load.html?url=http://www.northjersey.com/r?19=961&43=515347&44=234450391&32=4497&7=309037&40=http%3A%2F%2Fwww.northjersey.com%2Fnews%2FSecret_bunker_under_Prague_hotel_opens_to_public_.html&nid=4306612";
$datum = parse_url($test);
print_R($datum['query']);
以下是一个简单的解决方案:
url编码url变量后面的部分而不是整个url,您需要在url实际来源的位置而不是解析的位置进行更改:
$url_param_val = urlencode("http://www.northjersey.com/r?19=961&43=515347&44=234450391&32=4497&7=309037&40=http%3A%2F%2Fwww.northjersey.com%2Fnews%2FSecret_bunker_under_Prague_hotel_opens_to_public_.html&nid=4306612");
$new_url = "http://mywebsite.com/iframe_load.html?url=".$url_param_val;
使用urlencode()函数后,我得到的url如下:url=http%3A%2F%2Fwww.northjersey.com%2Fr%3F19%3D961。链接到iframe\u load.html时需要使用它,而不是在iframe\u load.html本身内。换句话说,当您访问iframe\u load.html时,iframe\u load.html?url=
之后的url应该已经编码。通过这种方式,iframe_load.html不会将URL拆分为多个部分。它只打印19=961@ARUN我尝试使用字符串$test
。请在没有url_encode()的情况下再次检查@ARUN请复制我的代码并执行它。并根据您的需要进行调整。如果我按原样复制您的代码,那么它就正常工作了。但是如果我像这样替换$test值,$test=$\u请求['url']代码>那么它就不工作了。@ARUN请不要使用$\u请求['url']
。使用代码中显示的第一行。