Extracting campaign data from Google Analytics cookies

Google Analytics in the last couple of years became a standard tool for web analytics as well a statndard tool for tracking marketing campaign. when a visitor hits first time your site Google Analytics sets different types of cookies in the visitors browser, one of these cookies is called utmz. this cookie holds quite valuable information like campaign name, campaign source, campaign medium, campaign term and campaign content.

to extract this data I used the following PHP method :

function getUtm(){
    $utm = array();
        $pattern = "/(utmcsr=([^\|]*)[\|]?)|(utmccn=([^\|]*)[\|]?)|(utmcmd=([^\|]*)[\|]?)|(utmctr=([^\|]*)[\|]?)|(utmcct=([^\|]*)[\|]?)/i";
        preg_match_all($pattern, $_COOKIE['__utmz'], $matches);
            foreach($matches[0] as $match){
                $pair = null;
                $match = trim($match, "|");
                list($k, $v) = explode("=", $match);
                $utm[$k] = $v;
    return $utm;

the returned array from this method will contain the following:
utmccn => campaign name
utmcsr => campaign source
utmcmd => campaign medium
utmctr => campaign term or keyword
utmcct => campaign content

Clean up Microsoft Word Html

Lately I had a task to publish some word documents with tables on a web site, after saving the file as filtered web site Microsoft Word produced a 250 KB file !! looking closely at the source code I notice their was 5 line of styles and unnecessary tags for every cell in the HTML table! fast search in Google resulted with Tidy, I installed the command line version as it was already included in Ubuntu 10.10 Maverick Meerkat repository, I run it and wow 30 KB result with clean and formated HTML.

here are the option I used in Tidy to cleanup the code:

bare: yes, clean: yes, drop-empty-paras: yes, drop-font-tags: yes, join-styles: yes, output-xhtml: yes, word-2000: yes

for more option check http://tidy.sourceforge.net/docs/quickref.html and for the online tool check Clean up HTML

How to install Sun Java JDK in Ubuntu 10.10 Maverick Meerkat

First you need to check that Ubuntu Partners repository is enabled in your apt sources list, open /etc/apt/sources.list and uncomment the following line:

deb http://archive.canonical.com/ubuntu maverick partner

Then in command line type

sudo apt-get update
sudo apt-get install sun-java6-jdk

As well you need to set Sun Java as default Java provider in your system by typing the following in command line

sudo update-alternatives --config java

You will be presented with the screen similar to this one:

There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                      Priority   Status
* 0            /usr/lib/jvm/java-6-openjdk/jre/bin/java   1061      auto mode
  1            /usr/lib/jvm/java-6-openjdk/jre/bin/java   1061      manual mode
  2            /usr/lib/jvm/java-6-sun/jre/bin/java       63        manual mode

Press enter to keep the current choice[*], or type selection number: 2

Select the option that has the path /usr/lib/jvm/java-6-sun/jre/bin/java and you are done.
to check if you are using the Sun Java provider type the following:

java -version

You should see a screen similar to the below

java version "1.6.0_22"
Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
Java HotSpot(TM) Client VM (build 17.1-b03, mixed mode, sharing)

SSH restrict access to user or group

When you have a public Linux server with Open SSH installed you will often find in you security logs failed login attempts from deferent ip’s most of them are hackers trying to brute force user accounts, one of security measures that can be added to Open SSH server is to restrict access to a specific user or specific group for example to allow user roger only to login to ssh you add the following line to /etc/ssh/sshd_config

AllowUsers roger

to restrict access to admin group add the following line

AllowGroups admin