alanchen Posted April 21, 2009 Share Posted April 21, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/155044-check-whether-a-page-is-google-cached/ Share on other sites More sharing options...
DeanWhitehouse Posted April 21, 2009 Share Posted April 21, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/155044-check-whether-a-page-is-google-cached/#findComment-815457 Share on other sites More sharing options...
taith Posted April 21, 2009 Share Posted April 21, 2009 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... Quote Link to comment https://forums.phpfreaks.com/topic/155044-check-whether-a-page-is-google-cached/#findComment-815459 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.