Jump to content

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...

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.