NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming > CODE
Reload this Page Google cache for your search site

CODE This forum is for posting code snippets and example scripts that aren't quite tutorials, but could be useful for others. You may post code snippets and/or completed scripts that you've written and want to share here.

Advanced Search


Reply
 
LinkBack Thread Tools
Old 01-08-2009, 11:08 AM THREAD STARTER               #1 (permalink)
P_R
NamePros Member
Join Date: Oct 2008
Posts: 26
P_R is an unknown quantity at this point
 



Google cache for your search site


I purchased a search script recently and for the cache it just had a hyperlink to googles cache, I didnt want this, I wanted it on my own site, as if it was my own cache, I couldnt find anything already made so I created this small php script.

To use the cache simply encode the URL you want the cache of

eg if you have $searchkw and $url in your current search script, and you want to create a hyperlink to the cache, you would simply do:

Code:
<?php
$enc_url = base64_encode($url);
echo"<a href=\"cache.php?u=$url&q=$searchkw\">Cached Version</a>\n";
?>
If you dont want keyword highlighting on, simply remove the &q=$searchkw

My example:
http://plerocs.com/result/20/chuck+norris
????: NamePros.com http://www.namepros.com/code/549069-google-cache-for-your-search-site.html

Click on cached page to see the script in action.


Code:
<?php
$url = $_GET['u'];
$url = base64_decode($url);
$kw = $_GET['q'];
$kw = str_replace(" ", "+", "$kw");
$useragent = $_SERVER['HTTP_USER_AGENT'];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://209.85.173.132/search?q=cache:$url+$kw");
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_REFERER,"http://google.com");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$contents = curl_exec ($ch);
curl_close ($ch);

$contents = str_replace("This is Google's cache of", "This is our cache of", "$contents");
$contents = str_replace(" <a href=\"http://www.google.com/intl/en/help/features_list.html#cached\" style=\"text-decoration:underline;color:#00c\">Learn more</a>", "", "$contents");
$contents = str_replace("<a href=\"http://209.85.173.132/search?q=cache:$url+$kw&amp;hl=en&strip=1\" style=\"text-decoration:underline;color:#00c\">Text-only version</a>", "", "$contents");
$contents = str_replace("These search terms are highlighted", "Your search terms are highlighted", "$contents");

if(strpos($contents, "</b> - did not match any documents.  <br>"))
{
echo"<h1>Error</h1>\n";
echo"<hr>\n";
echo"Unfortunately the page you wanted does not yet exist in our cache. You may visit the page by clicking the link below:<br>\n";
echo"<a href=\"$url\" rel=\"nofollow\">$url</a>\n";
}else{ 
echo"$contents";
}
?>
Use it on as many of your own sites, friends sites etc as you want, if you want to release it in a script please PM me.
P_R is offline   Reply With Quote
Old 01-08-2009, 06:44 PM   #2 (permalink)
Senior Member
 
nasaboy007's Avatar
Join Date: Jul 2005
Location: NJ
Posts: 1,219
nasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud of
 



Is it legal to use google's cache and claim that it's your own? (see first str_replace)
nasaboy007 is offline   Reply With Quote
Old 01-08-2009, 06:49 PM THREAD STARTER               #3 (permalink)
P_R
NamePros Member
Join Date: Oct 2008
Posts: 26
P_R is an unknown quantity at this point
 



Im not sure about the legality, if you have any worries I suggest you dont use the script. I myself am happy using the script, Im only doing what google does to every other webmaster. Anyway I created the script because its what I needed, I couldnt find another one out there, Use at your own risk.
P_R is offline   Reply With Quote
Old 01-08-2009, 06:56 PM   #4 (permalink)
Senior Member
 
nasaboy007's Avatar
Join Date: Jul 2005
Location: NJ
Posts: 1,219
nasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud of
 



Quote:
Im only doing what google does to every other webmaster.
I'm just saying that Google indexes the sites and hosts it on their own servers (the caches), so the "Google's cache" is really Google's cache, whereas the "our cache" is just Google's cache with their name changed to "our".
????: NamePros.com http://www.namepros.com/showthread.php?t=549069

I personally don't care, and I highly doubt Google will do anything about it, but I'm just curious.
nasaboy007 is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 06:02 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger