1

I try to check if a hotel is available through the Google Hotel Finder. I use the following PHP code:

<?php
//get date, in the future with $_POST

//get source
$source = file_get_contents('https://www.google.co.uk/hotelfinder/#search;l=london;d=2015-08-14;n=1;usd=1;h=17709217511794056234;si=;av=d');

//"Book a room" only shows when room(s) are available
if (strpos($source, "Book a room") !== false) {
    echo "Room(s) available";
} else {
    echo "Nothing available";
}

echo $source;
?> 

When I run this code in my server, Google Hotel Finder gives me the following error message: "Google Hotel Finder has not been optimised for your browser. For best results, please try Chrome, Firefox 3.5+, Internet Explorer 8+, Safari 4+". So Google detected that I was visiting the page trough PHP... Is there an way to ignore or bypass this "block"?

Jan Koekepan
  • 81
  • 1
  • 9

1 Answers1

1

You may try to send user agent info with header.

$options = array(
  'http'=>array(
    'method'=>"GET",
    'header'=>"Accept-language: en\r\n" .
              "Cookie: foo=bar\r\n" .  // check function.stream-context-create on php.net
              "User-Agent: Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.102011-10-16 20:23:10\r\n" // i.e. An iPad 
  )
);

$context = stream_context_create($options);
$file = file_get_contents($url, false, $context);

PHP file_get_contents() and headers

Community
  • 1
  • 1
mocak
  • 405
  • 2
  • 5
  • 12