[PHP] Check whether a page is Google Cached
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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Check whether a page is Google Cached
On Tue, Apr 21, 2009 at 8:29 AM, Alan Chen c...@datanumen.com wrote: 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 You've already laid out most of what needs to be done. I think the file_get_contents() function will be your best friend here, provided allow_url_fopen has been set to TRUE in your PHP configuration. Take the result you get back from that function and parse the 2nd line for This is Google#39;s cache of (I have made this assumption by looking at the source of http://www.google.com/search?q=cache:www.php.net). example.php === ?php $url = $_GET['url']; $res = file_get_contents('http://www.google.com/search?q=cache:' . $url); if($res strstr('This is Google#39;s cache of ', $res)) echo 'Your page is cached.'; else echo 'Your page is not cached.'; ? UNTESTED. Hope this helps. -- // Todd -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Check whether a page is Google Cached
Thank you so much. haliphax halip...@gmail.com дÈëÏûÏ¢ÐÂÎÅ:952625160904210738k494b892dlac3bb1b8e809f...@mail.gmail.com... On Tue, Apr 21, 2009 at 8:29 AM, Alan Chen c...@datanumen.com wrote: 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 You've already laid out most of what needs to be done. I think the file_get_contents() function will be your best friend here, provided allow_url_fopen has been set to TRUE in your PHP configuration. Take the result you get back from that function and parse the 2nd line for This is Google#39;s cache of (I have made this assumption by looking at the source of http://www.google.com/search?q=cache:www.php.net). example.php === ?php $url = $_GET['url']; $res = file_get_contents('http://www.google.com/search?q=cache:' . $url); if($res strstr('This is Google#39;s cache of ', $res)) echo 'Your page is cached.'; else echo 'Your page is not cached.'; ? UNTESTED. Hope this helps. -- // Todd -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php