Re: Check whether a page is Google Cached

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thank you so much.

"haliphax" <haliphax@xxxxxxxxx> дÈëÏûÏ¢ÐÂÎÅ:952625160904210738k494b892dlac3bb1b8e809fe82@xxxxxxxxxxxxxxxxx
> On Tue, Apr 21, 2009 at 8:29 AM, Alan Chen <ccw@xxxxxxxxxxxxx> 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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux