yes i love technology

PHP monitor server log

June 28th, 2007 by Pete

PHP monitor server log

Occasionally you'll be working on a webserver and not have SSH access to it. Below is a simple script I've written that reads a server log (in this case the error log) and outputs a portion of it to a webpage.

PHP:
  1. $no_lines = 25;
  2.  
  3. $filename = $_SERVER['DOCUMENT_ROOT']."/../logs/error.log";
  4. $handle = fopen($filename, "r");
  5. $contents = fread($handle, filesize($filename));
  6. fclose($handle);
  7.  
  8. $contents = trim($contents, "\n");
  9. $contentsArr = explode("\n", $contents);
  10. $size = sizeof($contentsArr);
  11. $n = $size - $no_lines;
  12.  
  13. <h1>monitor log</h1>
  14. ";
  15. <ol start=\"$n\">";
  16.  
  17. for ($n; $n<$size; $n++)
  18. {
  19.     <li>".$contentsArr[$n]."</li>
  20. ";
  21. }
  22.  
  23. echo "</ol>
  24. ";

Obviously in a production environment you'd want to add some sort of password protection to such a script.

/* Pete Graham */

Posted in Uncategorized, Website Development, php | 4 Comments »

Mailto Hyperlinks Stop Spam Bots!

June 28th, 2007 by Pete

Everyone hates spam, I hate it even more than most people. If you put an email address on a website, as a mailto hyperlink, then it's likely that spam bots will find this address and start sending annoying emails.

One way to get around this is to use a clever technique which I discovered over at SpamSpan.com. Instead of entering your email like a normal hyperlink use the code below:

HTML:
  1. <span class="spamspan">
  2. <span class="u">pete.graham</span> [at] <span class="d">domain-name.com</span>
  3. (<span class="t">Pete's Email Address</span>)
  4. </span>

A nifty piece of Javascript is then used to convert this html into a normal mailto hyperlink. Spam bots don't have Javascript enabled so wont register the link. If a visitor to your site have Javascript disabled they will see the link in the form below:
petegraham [at] domain-name.com (Pete's Email Address)

Email Spam Bot

# Pete Graham

Posted in Uncategorized, Website Development, spam | No Comments »

Vim Key Mappings

June 5th, 2007 by Pete

One of the things I always found awkward about Vim is stretching for the ESC key to get out of insert mode.

Here's a little trick that I like to add into my .vimrc file:

CODE:
  1. map  <space> i
  2. imap <S-space> <esc>

This will let you escape insert mode by pressing shift and space and enter insert mode by pressing space.

/* Pete Graham */

Posted in vim | No Comments »

IE7 Clicky Sounds Do my Nut in!

June 5th, 2007 by Pete

I'm not a fan of applications that use sounds effects, one of the first things I do when configuring a new PC is to set the Windows Sound scheme to 'No Sounds'. IE7 has the hugely annoying feature where a click sound is made when you click a link with the middle mouse button (this opens the link in a new tab).

My preferred browser of choice is Firefox but working in Web Development I often need to test website across a range of different browser, hence the need to use IE7. So far I have found no way of disabling this infuriating sound! Tortoise SVN is another offending program, there's nothing worst than having listening to some music interrupted with the 'Conflicting Files' sound!

If anyone finds any way of disabling the IE7 noise let me know and you will be my Hero for a whole day!

# Pete Graham

Posted in Uncategorized, Internet Explorer, Website Development | 3 Comments »