How Do I Embed / Iframe Another Website Into My Own?

How Do I Embed / Iframe Another Website Into My Own?
June 13, 2021 No Comments Tutorial rhalp10
Would you like to incorporate an existing site, such as google.com, into your website? Follow these few simple PHP scripts.

1. Create a sample "sampleindex.php" file to use as the other site's iframe.

<iframe src="http://localhost/sample_embed/preview.php" width="100%" height="100%" frameborder="0"></iframe> 

2. Create a new file called "preview.php" and paste the following code inside then save.

<?php 
$_GET   = filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING);

$_POST  = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);

$url = "google.com";

$curl = curl_init();

curl_setopt($curl,CURLOPT_URL,$url);

curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);

curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,false);

curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5);

curl_getinfo($curl, CURLINFO_HTTP_CODE);

$result = curl_exec($curl);


 

$info = curl_getinfo($curl);

if ($info["http_code"] == "400" ) {

echo "<h1>This page is not allowed to curl or having BAD request URL.</h1>";

}

else{

print($result);

} 

Here's a sample preview of this snippet.

Tags
About The Author
5 1 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x