Welcome to Geeklog, Anonymous Saturday, December 28 2024 @ 06:46 pm EST

Geeklog Forums

Random Quotes


Anonymous

Anonymous
After switching Hosts I am now receiving an "UNLINK" error with the Random Quotes feature. I made a temporary fix by changing the code (see below). This host does not permit file permissions 777 because of security concerns. The changes I made simply ignore the gotd.dat file (no caching) and gets the data from www.gotd.org website each time. This is not very polite as it puts extra load on their server so I'd consider this as a temporary fix only. I think what is required to fix this problem permanently is some new code that caches to the Mysql database instead of the qotd.dat file. I'm not that profecient yet but perhaps someone else could offer the code, PLEASE:-)) Temporary Fix================================== function phpblock_randqotd() { /* // First we check to see if a cached file exists // Then we check to see that the file is // 1) not older than $randcacheexpire // 2) larger than 40 bytes // We check for 40 bytes to make sure a blank file is not there, or an errorfile // There is probally a cleaner way of doing this, and faster... */ if (file_exists('/path to/qotd.dat') == TRUE) { $qotdsrc = '/path to/qotd.dat'; } else { $qotdsrc = 'http://www.qotd.org/cgi-bin/random.cgi'; } $blah = @fopen($qotdsrc, "r"Wink; $retsrt = ""; if ((isset($blah)) && ($blah != false)) { while(!feof($blah)){ $resp=fgets($blah,80); $retstr.=$resp; } } $sString = $retstr; if (file_exists('/path to/qotd.dat') == TRUE) { $sk = fopen('/path to/qotd.dat', "w"Wink; $fp = fwrite($sk, $sString); fclose($sk); } // Ok, lets strip out everything but the actual quote $sString = str_replace('A HREF','A TARGET="_blank" HREF',$sString); $sString = str_replace('</i> -','</i><p align="right">-',$sString); $sString = str_replace('BORDER=0ALT','BORDER=0 ALT',$sString); $sString = str_replace('http://www.qotd.org/env.gif','/path to your theme/images/mail.gif',$sString); $sString = strip_tags($sString, '<a><img><b><p><br>'); $sString = 'Courtesy of <a href="http://www.qotd.org/" target="_blank">qotd.org</a>:<br>' . $sString; if ($debugit > 0 ){ $sString = $sString . '<br> ' . $filemodtime . '<br> ' . $filemod .'<br> '.$currentdate.'<br>' .$difference; } return $sString; } //end phpblock_randqotd()> ==================================
 Quote

Anonymous

Anonymous
It's one thing not to cache data from a large corporate site, but qotd.org is a relatively small one. If you get a decent number of visitors, they may end up sending you a bill for the bandwidth used or banning your site. Why would you ever want to stay with a host which takes away your ability to use cache files? Sure, 777 is not very secure, but many people have to use this setting for a script to write to a file. As long as it isn't executable, who cares because the damage they could ever do is very limited.
 Quote

Status: offline

vinny

Site Admin
Admin
Registered: 06/24/02
Posts: 352
Location:Colorado, USA
The acutal cache file only has to have permissions 666, the directory that contains it does need to be 777 (but this really should be the default on a web server for all directories, even ones with security restrictions like your host). If you're web host will permit it, try using 666. If not, try using the following to cache: DB_query("INSERT INTO {$_TABLES['vars']} (name, value) VALUES ('quote_cache', $quote); and this to retrieve: $quote = DB_getItem($_TABLES['vars'], "name = 'quote_cache'"Wink; The problem with this is that the 'value' parameter (the quote) is limited to 128 characters. Which is why the author probably used a cache file in the first place (quotes < 128 characters are pretty rare). You could create your own table to get around this problem, but it's probably more effort than it is worth for a quote block... -Vinny
 Quote

Anonymous

Anonymous
Thank you Vinny, that sorted it out:-)) The 666 file permission was the solution. Your time is appreciated , fair yeh well!
 Quote

All times are EST. The time is now 06:46 pm.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content