Motyar

Get first link in Google search for a keyword using PHP

When you search Google for a KEYWORD and click "I am feeling lucky", you got redirected to this url -
http://www.google.com/search?hl=en&q=KEYWORD&btnI=1
You will be redirected to the first result link for that given KEYWORD.

I am not sure but knowing that first link for a KEYWORD may be useful for Search Engine Optimization or research etc.
Here is how we can get that link using PHP.

//Get the headers
$headers = get_headers("http://www.google.com/search?hl=en&q=KEYWORD&btnI=1", 1);
//The url for redirect
$url = $headers['Location'];

Labels: , , ,

By :

5 comments

#

Blogger Nitin Khanna says…

Pretty smart aren't we? Yours is the "Feeling Lucky" link on google!!!
 
#

Blogger Motyar says…

Yes @Nitin :)
 
#

Blogger Rmx says…

Quite evil but that's alright as long as I don't get to violated the rules
 
#

Anonymous Jack Stanly says…

that would be used as backlinks ?
 
#

Blogger HarshadS says…

Awesome man... thanks a lot Motyar... saved a lot of effort... just can't thank you enough.
- Harshad
 

Post a Comment