How to use http:// in https:// using iframe?

by cali_green , in category: Third Party Scripts , a month ago

How to use http:// in https:// using iframe?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by kadin , a month ago

@cali_green 

It is not possible to directly embed an HTTP content in a web page that is served over HTTPS using an iframe. This is because most modern browsers enforce the same-origin policy, which prevents loading HTTP content on an HTTPS page due to security reasons.


However, if you need to display content from an HTTP source on an HTTPS page, you can try using a proxy server to fetch the content and serve it over HTTPS. This can be achieved by creating a server-side script that retrieves the HTTP content and then serves it over HTTPS to the client.


Here's an example using PHP to proxy an HTTP content in an iframe on an HTTPS page:

  1. Create a PHP script on your server that fetches the HTTP content:
1
2
3
4
5
<?php
$url = 'http://example.com/content-to-fetch';
$content = file_get_contents($url);
echo $content;
?>


  1. Embed the PHP script in an iframe on your HTTPS page:
1
<iframe src="https://your-domain.com/proxy-script.php"></iframe>


By using this method, the HTTP content will be fetched and served over HTTPS, allowing you to display it in an iframe on your HTTPS page. Just make sure to secure your proxy server and sanitize the fetched content to prevent security vulnerabilities.