如何将iframe src设置为$_GET中的位置?
当前我正在尝试这个:
. htaccess
RewriteRule ^stream/(.*)$ index.php?p=stream&link=$1
stream.php/http://bbc.co.uk
<?php
echo '
<div class="container" style="height:1000px;">
<iframe src="'.$_GET['link'].'" frameborder="0" width="100%" height="100%"></iframe>
</div>
';
?>
这将iframe设置为127.0.0.1/stream/http://bbc.co。英国而不是bbc.co.uk
正如我在评论中指出的那样,您需要重写php文件以删除.php
,以便您发布的规则匹配,例如:
RewriteRule ('w+).php $1
RewriteRule ^stream/(.*)$ index.php?p=stream&link=$1
这意味着你的链接将被重写为:
http://example.com/stream.php/http://bbc.co.uk
http://example.com/stream/http://bbc.co.uk
http://example.com/index.php?p=stream&link=http://bbc.co.uk
那么你的php将输出:
<div class="container" style="height:1000px;">
<iframe src="http://bbc.co.uk" frameborder="0" width="100%" height="100%"></iframe>
</div>
正常工作
url本身不正确。它的格式应该是
stream.php?link=http://bbc.co.uk
然后你会得到它:
$_GET['link']
另一种方法是存储上述get变量与相应url的映射:
ie。
var urlsMapping = {"bbc":"http://bbc.co.uk","toi":"http://timesofindia.indiatimes.com"}
然后将url设置为:
stream.php吗?链接= bbc
设置iframe src为
urlsMapping[<?=$_GET['link']?>]
试试这个
RewriteRule ^stream/(.+)$ index.php?p=stream&link=$1 [L,QSA]
我使用preg_replace
修复了这个问题可能不是最好的选择,但它确实有效。
<?php
$link = preg_replace('~http:/~si', '', $_GET['link']);
echo '
<div class="container" style="height:1000px;">
<iframe src="http://'.$link.'" frameborder="0" width="100%" height="100%"></iframe>
</div>
';
?>