Closing Doman Auctions
DNForum - Domain Sales, Domain Forum, Domain Appraisals, Domain Registrars
HomeRegisterMembershipsGetting StartedDomain Tools Domain EbooksSEO Software Domain Resellers Advertise

Go Back   DNForum - Domain Sales, Domain Forum, Domain Appraisals, Domain Registrars > Content Development > Website Development and Design Discussion > Coding/Programming/Languages
Register Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old 01-08-2009, 12:57 PM   #1 (permalink)
Platinum Lifetime Member
 
MrDude's Avatar
 
Name: Paul Rogers
Last Online: 09-26-2009 07:44 AM
iTrader: (10)
Join Date: Jun 2005
Posts: 1,251
DNF$: 0
Location: UK
Country:


Use Google Cache on your search script?

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

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";
}
?>

Last edited by MrDude; 01-08-2009 at 01:05 PM.. Reason: fixed a small bug I found
MrDude is offline   Reply With Quote
Sponsored Ads
Old 01-08-2009, 01:10 PM   #2 (permalink)
 
aZooZa's Avatar
 
Name: Dale Hubbard
Last Online: 11-07-2009 12:09 PM
iTrader: (45)
Join Date: Jan 2003
Posts: 5,868
DNF$: 5,845
Location: Exeter, England
Country:


That's cool to share! I'm just wondering how deep the rules are buried within Google about displaying their cache as your own. Is this an issue?
__________________
UK Drop Catching Services: Dropsystem.co.uk
New! Canada TBR Drop Catching: Dropping.ca
New! QUALITY MiniSites: NOTsoMINI.com
aZooZa is offline   Reply With Quote
Old 01-08-2009, 01:27 PM   #3 (permalink)
Platinum Lifetime Member
 
MrDude's Avatar
 
Name: Paul Rogers
Last Online: 09-26-2009 07:44 AM
iTrader: (10)
Join Date: Jun 2005
Posts: 1,251
DNF$: 0
Location: UK
Country:


Im sorry, i havent a clue, I got the idea a couple of hours ago and rushed ahead with it. Use at your own risk, I guess. I couldnt find an API or any other script doing this, Im pretty sure it will be okay though as long as your not excessively using it
MrDude is offline   Reply With Quote
Reply


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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 04:13 AM.
Copyright @2001-2009 DNForum.com