By Norvert John Abella


2014-08-08 14:53:57 8 Comments

I have a php script that will return a google search but it gives me the HTTP error.

  if (strstr(file_get_contents("http://www.google.com/search?q=site:http://". $url ."&gws_rd=ssl"), 'did not match any documents.')) 
{
  return "No";
}

else {

    return "Yes";

}
A PHP Error was encountered

Severity: Warning

Message: file_get_contents(http://www.google.com/search?q=site:http://google.com&gws_rd=ssl): failed to open stream: HTTP request failed! HTTP/1.0 503 Service Unavailable

Filename: libraries/google_index.php

Line Number: 8

error : HTTP request failed! HTTP/1.0 503 Service Unavailable. how can i force this or something so it will get the contents.

2 comments

@mpinsonfr 2018-11-05 15:56:56

Try encoding the whole URL, like:

 $string = "google.com/search?q=site:". urlencode($url ."&gws_rd=ssl")

@lxg 2014-08-08 15:18:35

If you put an URL as GET parameter of another URL, you must urlencode() it. Otherwise, some characters like ? or & will be considered as parts of the main URL.

@Norvert John Abella 2014-08-08 15:31:07

thanks for the reply. but actually all of this "google.com/search?q=site:http:/". $url ."&gws_rd=ssl" is part of the main url

@NickG 2014-08-08 15:34:27

@NorvertJohnAbella Well you still need to encode it. Or you'll get the error you're seeing.

@Norvert John Abella 2014-08-08 15:40:21

@NickG yes, i already encode it $string = "google.com/search?q=site:". urlencode($url) ."&gws_rd=ssl"; but still getting the error

@NickG 2014-08-08 15:48:42

Perhaps you should post an example URL which isn't working. Does it depend on the value of $url? Does it do the same thing if you don't search on "site:".... ie if you search on a keyword?

Related Questions

Sponsored Content

16 Answered Questions

34 Answered Questions

[SOLVED] Reference - What does this error mean in PHP?

2 Answered Questions

[SOLVED] file_get_contents and error codes

10 Answered Questions

18 Answered Questions

4 Answered Questions

2 Answered Questions

[SOLVED] file_get_contents - failed to open stream: HTTP request failed

0 Answered Questions

0 Answered Questions

file_get_contents with HTTPS

1 Answered Questions

[SOLVED] 503 Service Unavailable on Google Search

  • 2015-08-03 19:50:17
  • wadhwasahil
  • 1017 View
  • 0 Score
  • 1 Answer
  • Tags:   php

Sponsored Content