Jump to content

Check whether a page is Google Cached


alanchen

Recommended Posts

Hi, everyone,

 

I want to write a small PHP script test.php that can determine whether a

webpage is Google Cached.

 

Assuming it is uploaded to www.mysite.com, and I want to use it to check

whether www.yoursite.com is google cached.

 

It works as follows:

 

The user input the query:

 

http://www.mysite.com/test.php?site=www.yoursite.com

 

The php script will send the following request to the browser

 

http://www.google.com/search?q=cache:www.yoursite.com

 

in the background.

 

And if the returned result contains a string "This is Google's cache of",

then the page is cached, so the php script can display

 

"Your site is cached by Google"

 

otherwise, it will say

 

"Your site is not cached by Google"

 

Just wonder how to implement such a feature, can anyone write a simple

sample so that I can use as a startpoint as I am a totally new guy in PHP

coding

 

Thanks to all of you so much

 

Alan

 

 

Link to comment
https://forums.phpfreaks.com/topic/155044-check-whether-a-page-is-google-cached/
Share on other sites

This isn't the best thing to start learning PHP with but if you want to do this you will need to look into

PHP $_GET/get

PHP forms (if you want one)

and then maybe file_get_contents and maybe a regex or just some string functions to search for the term in the results which say whether it is cached

yer gunna want to use cURL for this... php.net/curl

 

ob_start();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.google.com/search?q=cache:www.yoursite.com');
curl_exec($ch);
curl_close($ch);
$o=ob_get_contents();
ob_end_clean();

 

that would set the entire page specified into the $o variable... in which you just need a simple eregi() to check for the 'This is Google's cache of' string...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.