Archive for the ‘Tutorials’ Category

Jan

30

We recently ran into a situation where one of our users was receiving a large amount of spam to their forwarded email account. Our setup is a dedicated server running Simple Control Panel at Godaddy. We handle email for a few clients and this one in particular was receiving 100’s of spam emails every hour.  Pretty much as soon as we set up this client, we started hitting our 1,000 SMTP Relay limit which prevented us from sending any further emails for any other client on the server.

There is a simple fix to this that I had a difficult time finding so I decided to create a post on this for anyone else who might run into this issue.

The first thing I tried was to turn on SpamAssassin through the Simple Control Panel (log in to your control panel, choose “Email” from the “Server Configuration” section, and choose “Filter incoming email using SpamAssassin”).  The result of this is that SpamAssassin started analyzing the emails coming in and marking them as Spam.  This didn’t fix the problem because the emails were not being dropped, but were instead being forwarded onto the receipient, just now with the “SPAM” designation in the message subject.

The only solution I discovered was to utilize Postfix’s header_checks.  This uses a regular expression to check the header of the email message and then apply a rule to the message accordingly.  Here’s what we did.

  1. edit the /etc/postfix/header_checks file.
  2. add the following line to the bottom of the file:

    /^X-Spam-Flag:.YES/ DISCARD spam

  3. edit the /etc/postfix/main.cf file an make sure the following line is in your file (it may just be commented out):

    header_checks = regexp:/etc/postfix/header_checks

  4. Now restart your postfix process by using the following command:

    postfix reload

What this does is look for the existence of “X-Spam-Flag” in the header of the message.  This flag is put there by SpamAssassin, so it is important that SpamAssassin is running.  Once it sees the “X-Spam-Flag”, it will discard the message.  This will effectively prevent your server from forwarding any spam emails onto your user’s email accounts.  So far this has worked out well for us.

Oct

6

I recently got a request from a client of mine to setup two different wordpress blogs for her company and then display the posts from both blogs in a single list on the home page of her web site. I wasn’t able to find much documentation of people doing this type of thing through various searches, so I figured I’d post an entry on it when I finished. As a disclaimer, I’m sure that this can be done more efficiently or in less code. If you have a better way to do it, please leave me a comment. I’m always open to learning new techniques.

Read the rest of this entry »

Sep

29

I’ve run into situations where I’ve installed content management systems for customers who like to add their own content and/or copy content from documents they’ve created. Often, this results in them copying non-ASCII characters such as smart quotes, elipsis, or em dashses. I’m not sure why (maybe someone can educate me by posting a comment below) that PHP can’t handle these characters, but I’ve come up with a way to replace these characters with characters or character sequences that PHP understands. The function is below.

function cleanString($string) {
  $find[] = '“';  // left side double smart quote
  $find[] = '”';  // right side double smart quote
  $find[] = "‘";  // left side single smart quote
  $find[] = "’";  // right side single smart quote
  $find[] = '…';  // elipsis
  $find[] = '—';  // em dash
  $find[] = '–';

  $replace[] = '"';
  $replace[] = '"';
  $replace[] = "'";
  $replace[] = "'";
  $replace[] = '...';
  $replace[] = '-';
  $replace[] = '-';

  return str_replace($find, $replace, $string);
}

The function essentially is a very simple string replacement that attempts to match an invalid character with a valid character and output the change.  This will prevent the weird diamonds or boxes that you may be seeing in text output using “echo” in php.

Sep

16

See The Demo

I recently completed a website design project for a local austin company that involved creating a simple image slideshow on the login page of their application. These types of slideshows have traditionally been done using an animation toolkit or framework such as Adobe’s Flash product. Starting around three years ago, I was introduced to script.aculo.us which provided the ability to use effects with DOM elements to provide cool animations.

Just within the last year, I’ve started working more with jQuery and have been introduced to the slew of extremely cool plugins.  The newest one I’ve come across is jQuery Cycle.  Using this plugin and 9 lines of javascript code, I was able to create an extremely simple but cool image slide-show for the website project for my client.

The first step in building the slideshow is to create the html element that will hold the images for your slideshow:

<div id=”slideshow”>
  <img src=”slides/slide-1.jpg” border=”0″/>
  <img src=”slides/slide-2.jpg” style=”display:none”/>
  <img src=”slides/slide-3.jpg” style=”display:none”/>
</div>

The above is a simple list of images within the div element that’s identified by the “slideshow” id.  This will enable jQuery to pick up the “slideshow” element and then iterate over the <img> elements within it when building the slideshow.

The second step is to write the actual javascript that will use the plugin to build and run the slideshow:

$(document).ready(function(){
  $(function(){
    $(“#slideshow”).cycle({
      fx: ‘fade’,
      speed:2500,
      timeout: 1000
    });
  });
});

A little explanation on what is happening here: The $(“#slideshow”) is grabbing the slideshow div element and feeding the images into jQuery Cycle Plugin’s initialization.  The plugin is applying the fade effect (see more information on the effects you can use here) at a speed of 2500 milliseconds and a timeout of 1000 milliseconds.  Speed controls how long the transition takes to complete and timeout controls the time between slide transitions.  You can find more information on the options for the plugin here.

All-in-all, this has turned out to be a ridiculously easy way to code up a simple slideshow.  You can enhance your slideshow in all sorts of ways such as loading your images through ajax after the page loads, randomizing ordering, and providing new transitions.  All without having to worry about motion tweens in Flash!

See the Demo