Google Last Cached Date Finder In PHP

When Google looks at a page it takes a snapshot of that page and uses this to match against the query a user entered. To view these cached pages run a Google search and look at the Cached link next to the green URL text of the result. When you view the cached page Google will also give you a date that the page was last cached on. This can be used as a metric of your sites importance as the more often the site is cached, the more favourable Google views your page.

Taking a reading of this metric can therefore be useful, which is why I set about to create a class to retrieve this result.

Download the Google Cache class here.

The class works by constructing a query string with a given URL, which it then uses to download the cached page from Google. It then detects if a date string has been found and if so returns this. If anything went wrong along the way then the function will return false. In an effort to stop Google getting angry with you for trying to spam their site with multiple requests the class will also randomly select from a series of addresses. There is only one address (a single IP address) at the moment, but to add more simply add them to the $googleAddresses array at the top of the class. Every time the getLastCached() function is run a new address will be randomly selected. If you enter an address that causes an error then the function will return false.

Use the class in the following way:

$googleCache = new GoogleCache();
$date = $googleCache->getLastCached("http://www.bbc.co.uk/");

This will return the date when the BBC home page was last cached, which should be very recent.

Comments

your nice script has worked for me for a few months but now it has stopped working without changing anything. I've looked into the codes but couldn't find how to resolve this problem. Would you please help. Many thanks,
Permalink
It's probably because Google have changed something that this class is looking at. I'll take a look and see what I can do :)
Name
Philip Norton
Permalink

Change the following line:

protected $googleAddresses = array("74.125.77.132");

into:

protected $googleAddresses = array("webcache.googleusercontent.com");

Permalink

Hello,

Your script worked great for me but now it stopped working... something wrong?

Kind Regards,

Peter 

Permalink

As another commenter posted above (thanks KDS) if you change the IP address used in the property $googleAddresses to be webcache.googleusercontent.com then it seems to work nicely.

I have updated the class to incorporate this change so you can download it again if you wish :)

Name
Philip Norton
Permalink

it's really very help ful and working nice.

Now can you give some idea to get result for multiple urls at one time.

 

Permalink

Hello All,

Does anybody know a good position checker php script? This will save me a lot of time every morning...

Thanks in advance!

Kind Regards,

Peter

Permalink

It's tricky. They have no API for this and it's against their terms and conditions so they will make it deliberately difficult for you to scrape their site for content.

That said, it is possible. I've done it in the past and have done all sorts of things to get around the checks that Google does to stop you.

Name
Philip Norton
Permalink

I tried it in my localhost and run it for multiple urls.

It's working proper but when I upload it in my server it's show me an the default date of the server.

It's not giving me proper output please anyone help me to solve this out.

Permalink

Hey I also face the same problem.

I had made it for multiple site and it's working perfect and show proper output but when I upload it at live server

it show me blanke value.

It show me nothing so if you find anything so please inform me.

Permalink

Add new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
1 + 0 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.