简体   繁体   English

https和来自其他网站的图片。 如何在不修改.htaccess文件的情况下使用php或javascript删除http图像的警告?

[英]https and images from another site. How to remove warnings for http images using php or javascript without modifying .htaccess file?

I have an ssl certificate on my web-site. 我的网站上有ssl证书。 Once images are loaded on the page from another site, it causes warnings kind of " the page contains both secure and nonsecure items ", so you have to press OK or you see "broken" ssl connection in the browser. 一旦图像从另一个站点加载到页面上,它会导致警告类型“ 页面包含安全和非安全项 ”,因此您必须按OK或在浏览器中看到“已损坏”的ssl连接。 One of the ways to escape that warnings is to use http page instead of https, correct? 逃避警告的方法之一是使用http页而不是https,对吗?

But, as far as I know, there is another way to exclude that warnings using php or just using javascript. 但是,据我所知,还有另一种方法可以使用php或仅使用javascript来排除警告。 I believe the images are loaded to the temporary folder on my server and are loaded as https images at the same time. 我相信图像被加载到我服务器上的临时文件夹中,并同时加载为https图像。 Could anybody tell me the best way to do that? 有人能告诉我最好的方法吗? Browsing the forum didn't help me a lot. 浏览论坛对我帮助不大。 Thank you. 谢谢。

So, how to load 那么,如何加载

<?php echo '<img src="http://www.not_my_site.com/image.jpg" alt="">'; ?>

with no warnings on my page https://my_site.com/index.php ? 在我的页面上没有警告https://my_site.com/index.php

You cannot surpress the error as it's a browser thing. 你不能压抑错误,因为它是一个浏览器的东西。

The only way would be to wrap those calls using an https call on your site. 唯一的方法是在您的网站上使用https呼叫包裹这些呼叫。 Something like: 就像是:

<?php echo '<a href="https://my_site.com/external.php?resource=http://www.not_my_site.com/image.jpg" alt="">'; ?>

You will have to write the external.php script to make the request on the client's behalf, and then return the content over your existing SSL connection. 您必须编写external.php脚本以代表客户端发出请求,然后通过现有SSL连接返回内容。 You only NEED to do this for external HTTP-only resources. 您只需要为外部HTTP资源执行此操作。

The process would work as follows: 该过程将如下工作:

  1. The end user's web browser makes an HTTPS request to your external.php script. 最终用户的Web浏览器向您的external.php脚本发出HTTPS请求。
  2. Check for a saved copy of the resource. 检查资源的已保存副本。 If you've got it cached then skip to step 6, returning the cached resource. 如果您已将其缓存,则跳至步骤6,返回缓存的资源。
  3. Your server forwards on the call to the HTTP resource specified as the resource . 您的服务器转发对指定为resource的HTTP资源的调用。
  4. The remote server responds to the request. 远程服务器响应请求。
  5. Save a copy of the resource for caching. 保存资源的副本以进行缓存。
  6. Your web server external.php script then returns that response over the SSL connection. 然后,您的Web服务器external.php脚本通过SSL连接返回该响应。

The web browser only makes 1 request, your web server just has to make an additional one. Web浏览器只发出1个请求,您的Web服务器只需要另外一个。

This is the only way you'll be able to get rid of the message. 这是你能够摆脱信息的唯一方法。


Looks even simpler to retrieve the image: use curl to download indirect image file 检索图像看起来更简单: 使用curl下载间接图像文件

It happens cause your making non-secure (HTTP) calls from a secured-page (HTTPS). 它会导致您从安全页面(HTTPS)进行非安全(HTTP)调用。

try changing your code to: 尝试将代码更改为:

<?php echo '<a href="https://www.not_my_site.com/image.jpg" alt="">'; ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM