【问题标题】:Set iframe location as the location in the $_GET element将 iframe 位置设置为 $_GET 元素中的位置
【发布时间】:2014-07-03 05:30:58
【问题描述】:

如何正确地将 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.uk,而它应该只是转到 bbc.co.uk

【问题讨论】:

  • 听起来是一种很好的方法来诱使人们认为我的网站是您网站的一部分...
  • 什么,即使您的网站在 URL 中清晰可见?
  • 这是唯一的重写规则吗?我没有看到任何可以将stream.php 变成stream 的东西。
  • 不,不是,我已经删掉了大部分,因为它太大了抱歉,我可以回显 $_GET['link'] 并通过转到 /stream 来访问 stream.php跨度>
  • 由于某种原因,当我回显 $_GET['link'] 时,它返回 http:/bbc.co.uk 而不是 bbc.co.uk(在 http: 之后是一个正斜杠而不是两个)

标签: php html .htaccess iframe


【解决方案1】:

正如我在评论中指出的那样,您需要重写 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>

按预期工作。

【讨论】:

  • 这个有同样的问题,它只在http:之后显示一个正斜杠而不是两个。
  • @user1626410 it only shows one forward slash after http: instead of two 在哪里?重写的每个阶段在源代码中都有 2 和 2 显示。
  • 在 iframe src 中显示
  • @user1626410 我无法重现您的问题。完全按照我的说明运行代码,并删除我帖子中没有的所有 RewriteRules。
【解决方案2】:

网址本身不正确,即。它应该是

的形式
stream.php?link=http://bbc.co.uk

然后你就会得到它:

 $_GET['link']

另一种方法是将上述get变量的映射存储到相应的url:

即。

var urlsMapping = {"bbc":"http://bbc.co.uk","toi":"http://timesofindia.indiatimes.com"}

然后让你的网址像:

stream.php?link=bbc

将 iframe src 设置为

urlsMapping[<?=$_GET['link']?>]

【讨论】:

  • 重点是将url stream.php/otherurl 改写成index.php?p=stream&link=otherurl
【解决方案3】:

试试这个

RewriteRule ^stream/(.+)$ index.php?p=stream&link=$1  [L,QSA]

我希望这会对你有所帮助。

【讨论】:

    【解决方案4】:

    我使用 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>
     ';
    ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-12-05
      • 1970-01-01
      • 2016-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多