0

i have the following php code:

<?php
require_once("support.php");

$query = $_POST["search"];

$google = "http://www.google.com/search?q=" . $query;
$bing = "http://www.bing.com/search?q=" . $query;
$yahoo ="http://search.yahoo.com/search?p=" . $query;
$ask = "http://www.ask.com/web?q=" . $query;

$body= "<html><head>";
$body .= "<script src=\"scripts.js\"></script>";
$body .= "</head>";
$body .= "<frameset rows=\"50%,50%\" cols=\"50%,50%\" >";
$body .= "<frame src=\"$google\" />";
$body .= "<frame src=\"$bing\" />";
$body .= "<frame src=\"$yahoo\" />";
$body .= "<frame src=\"$ask\" />";
$body .= "</frameset>";

$body .= "</html>";

echo $body;
?>

which produces the following html:

<html>
  <head>
      <script src="scripts.js"></script>
  </head>
  <frameset rows="50%,50%" cols="50%,50%" >
       <frame src="http://www.google.com/search?q=adf" />
       <frame src="http://www.bing.com/search?q=adf" />
       <frame src="http://search.yahoo.com/search?p=adf" />
       <frame src="http://www.ask.com/web?q=adf" />
  </frameset>
</html>

when i open this in google chrome, i get 4 frames with the expected content, from the above url's. but in the first frame, who's src is from google, i get nothing; just a blank frame. any idea what is going on here?

Thanks

user1366730
  • 1
  • 1
  • 1

3 Answers3

4

Google sets their X-Frame-Options header to SAMEORIGIN, which forbids non-Google.com sites from embedding their pages. Most modern browsers respect this setting.

ceejayoz
  • 176,543
  • 40
  • 303
  • 368
0

You can use the developer tools as a chrome extension. Firebug will also do a similar job. Hit Ctrl+Shift+J from your webpage and chrome should pop up with the developer tool interface.

From here, click Console, and check for any error messages. I remember hitting a similar problem with Same-Origin x-frame options - but this was for GDocs where there was authentication issues. There was no simple workaround in my case, and I used a separate tab.

This thread might also help: How can I embed a Google Docs collection in an Iframe?

Community
  • 1
  • 1
nonshatter
  • 3,347
  • 6
  • 23
  • 27
0

You can make the server download the google search result page, and feed it to your frame, using curl.

<?php 
function getHtml($url) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);    
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);  
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
    $result = curl_exec($ch);
    curl_close($ch);
    return $result;
}

$google = getHtml("https://encrypted.google.com/search?q=".$query) or die("dead!");
#....
?>
Nicolas A. T.
  • 133
  • 1
  • 10