PHP and Google Search Engine

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
replyprabhat
Forum Newbie
Posts: 4
Joined: Wed Nov 05, 2008 9:58 pm

PHP and Google Search Engine

Post by replyprabhat »

HI All,
I am using php file_get_contents/CURL to access the google result. But, when I execute query
for e.g. http://www.google.com/search?q=aviation ... ia&start=0 using CURL and again if I directly access the url through the browser and compare both the results from php curl and in the browser, they are different.

Does anybody know, what is happened? I have loss more than 2 days in it.
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Re: PHP and Google Search Engine

Post by infolock »

post your results please from both, and let's see what we can give you (don't have time to do it from scratch myself...)
replyprabhat
Forum Newbie
Posts: 4
Joined: Wed Nov 05, 2008 9:58 pm

Re: PHP and Google Search Engine

Post by replyprabhat »

thankx for ur reply
this is my code

$html=file_get_contents("http://www.google.com/search?q=aviation ... ia&start=0");
echo $html;

the result it display is different from the result that i search directly in google.com for "aviation security australia"

but, if i just copy the same url "http://www.google.com/search?q=aviation ... ia&start=0" and paste it in the browser, the result is same for that i searched in google.
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Re: PHP and Google Search Engine

Post by infolock »

(please delete this post of mine, is a duplicate...)
Last edited by infolock on Wed Nov 05, 2008 10:23 pm, edited 1 time in total.
replyprabhat
Forum Newbie
Posts: 4
Joined: Wed Nov 05, 2008 9:58 pm

Re: PHP and Google Search Engine

Post by replyprabhat »

yeah thats true..i'm trying from both way..but the result is same whether i use curl or file_get_contents
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Re: PHP and Google Search Engine

Post by infolock »

thought you had a curl implimentation you were working with too?

Either way, it's because you aren't on their server. They use paths like /go/to/here/for/image for images. since you are'nt on google.com domain, you'll have to supply full path where it doesn't exist. so, the results will be the same, but images, css, etc that they don't supply full path to in their source code will need to be re-manufactured (or copy catted to your own server directory listing)
replyprabhat
Forum Newbie
Posts: 4
Joined: Wed Nov 05, 2008 9:58 pm

Re: PHP and Google Search Engine

Post by replyprabhat »

but if i tried using google.com.au in curl, it gives me exact result. The only problem is with US server. Is there any way to access for US only. I tried finding the google.com IP and pass it but still doesn't work.
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Re: PHP and Google Search Engine

Post by infolock »

there are multiple google teams across the usa and world for that matter. not all of them (unfortunately) follow the same rules of the team, and ones with their own server get to write how they deem fit. including writing base paths instead of full paths =\.

in this case, all you can do is replace base paths with full paths. that or point it only to au page in your code. or, setup filestructure equal to that of the us server along with the files they need (or redirect pages or something) to make up for it when a base path is called. that's all you can do.
j4IzbInao
Forum Newbie
Posts: 9
Joined: Tue Oct 14, 2008 6:07 am

Re: PHP and Google Search Engine

Post by j4IzbInao »

I'm not sure if this is what you're talking about but it sure sounded like that the searchresults differed from when using php to fetch results to what you saw when you went to google via your webbrowser.

If that is what you're talking about it is because of the fact that google has multiple datacenters and you do not always get connected to the very same datacenter so two people, in the same office, can get different search-results even though they're using the exact same search-terms & google-website.
Post Reply