【问题标题】:Hide URL of the website I am fetching data from隐藏我从中获取数据的网站的 URL
【发布时间】:2016-10-22 08:15:58
【问题描述】:

我正在使用第 3 方 API,它通过公共 URL 向我们提供数据。我希望这些数据出现在我的网站上,而用户不知道从中获取数据的确切位置。

示例: 要从此 URL 获取的数据:https://example.com/1477116779.16443511_0.mp3 在此显示的数据:www.zigsaw.in/telephonicinterviews/1477116779.16443511_0.mp3

我尝试使用 IFrame

<iframe src="https://example.com/1477116779.16443511_0.mp3" width="100%" height="100%" frameborder="0" scrolling="no" />

但它允许“在新标签页中打开链接”,从而显示原始页面来源

背景:我们是一家招聘初创公司,不希望外面的人知道我们的小公司。最终,他们会知道,但我更愿意提前 3-4 个月。

附: :下载数据并将其上传到我的服务器也是一种解决方案,但我不想给我的托管造成不必要的负担。由于这些是音频文件,因此会占用大量空间。

【问题讨论】:

    标签: php url iframe mp3


    【解决方案1】:

    没有针对该问题的 HTML 解决方案 - 您可以将 URL 重写到您的服务器,但是您需要一个脚本来获取原始 url 并显示数据 - 类似这样:

    <?php
    header('Content-disposition: attachment; filename=filename.mp3');
    header('Content-type: application/octet-stream'); // adjust this to your real fileType
    header('Content-type: audio/mpeg'); // use this for mp3
    echo file_get_content('http://your-url.com/123');
    ?>
    

    然后链接到这个脚本 - 瞧 - 用户只看到您的网址,但看不到原始网址。脚本正在传递数据。

    【讨论】:

    • 效果很好。谢谢 :) 知道如何播放音频而不强迫用户下载吗?
    • 查看我的编辑 - 使用其他 Content-Type "audio/mpeg"。
    • 它仍在下载
    【解决方案2】:

    您可以禁用对元素的右键单击,但这不会阻止某人在 inspect element 选项卡中看到该 url,甚至无法在页面原始 html / page source 中查看它。

    因此,要仅禁用 iframe 元素的右键单击,请使用此选项。 (按钮1是普通点击,2是右键。)

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    <script>
        $("iframe").click(function(event) {
            if(event.button==2) {
                return false;    
            }
        });
    </script>
    

    【讨论】:

      【解决方案3】:

      如果您使用 Nginx 作为您的 Web 服务器,您可以在服务器级别代理请求。创建一个充当 API 代理的子域。

      简单配置:

      http {
          sendfile        on;
      
          keepalive_timeout  2000;
      
          server {
              listen       80;
              server_name  data.example.com;
      
              location / {
                  proxy_pass https://www.zigsaw.in;
                  proxy_pass_request_body on;
                  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
              }   
          }
      }
      

      阅读 Nginx 文档以了解有关 ngx_http_proxy_module 的更多详细信息。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-01-19
        • 1970-01-01
        • 2013-10-11
        • 2012-08-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-02-21
        相关资源
        最近更新 更多