Articles

Regular check for changes of MySQL database - Below outlined script implements regular check of a MySQL database for modifications. Modifications can be detected using two approaches - last modification timestamp of a table or row count...

Serving pre-compressed js and css when mod_deflate is not available or not desirable. - Serving compressed static contents like javascript and CSS files has become a must-have for every modern website. It helps mitigating the growing size of client side scripts in the modern Web 2.0...

Grepping multiline log messages - Grep is very useful when browsing a lot of log messages for specific terms. However some applications don't always adhere to the concept one message - one line. So sometimes you end up with...

Basic file operations. Searching for string in a file line by line - Basic file operations like open, read, write etc. are essential part of every programming language. In this article we'll make a comparison between implementations in several different...

MySQL exercises: getting the previous and the next message for each thread - Here's an interesting problem: we have a table thread and table messages, containing messages threaded in each thread. The question is if we have given message id, how to retrieve this message...

MySQL search and replace across the whole database - When changing the domain of certain website or other similar operations at some point it comes to search and replace of certain term across a database. That is not in certain table or column,...

Class members ordering convention - When creating a class with several members at some point we come to the decision how to order the members. For example let's take the following Java class: public class MyClass {...

Implementing simple visitor counter in PHP. File locking functions and their usage - There are several cases when you'd like to have the current visitor number on your web page. Whether it's just for the label "You are visitor number 4" or for having some special...

Creating readonly HTML checkbox and still have its value submitted - There are two ways for preventing changes of HTML form elements values. One can either set readonly="readonly" or disabled="disabled" . Those two have only one difference...

Date format in RSS feeds - When making our own RSS feed generators, the most awkward thing is the date format in use for each item publication date. The format in question is RFC 822 . When we don't use the correct date...

Iteration over Java Map elements - Map implementations are very useful structures for storing key -> value associations. Mostly they are used for getting the value associated with specific key. But sometimes we want to...

Yet another anti spam bot protection technique for HTML forms - Anti spam bot protection evolves through time but so does the bot logic. Aftermath is that for real people it's more difficult to submit a contact form, comment or request with all those blurry...

Creating horizontal HTML lists with CSS - This article covers horizontal HTML lists and some popular applications. We are used to see the HTML lists, <ul> or <ol>, as buletted lines. However with a few CSS tweaks we can...

Automatically re-execute a command by a given time interval in bash - There are several use cases where we need to execute a command every 5 seconds or so. Typical examples are watching dynamic directory content, monitoring how a file grows, monitoring...

Accessing values of variuos HTML form elements - HTML form elements are commonly spread in websites - from simple contact forms to complex rich internet applications (RIA). Though all of them can be accessed via javascript the actual code...

Handling large XML files in PHP - Handling XML files in PHP is relatively easy when it comes to limited document size. Let's have the following example xml document with products: <?xml version="1.0"...

Merging a folder of images into single PDF file - Imagine you have a folder with many images (scanned document or photo album) and you want to generate single file containing all of them and send it by email for example. This can be achieved...

Changing awk delimiter and processing CSV files - One of the functions of awk is to split line of data by white spaces and extract only the desired parts. As such this tool is very suitable for handling comma separated values ( CSV ) files. The...

Stripping HTML comments from a string in PHP - Bellow is a PHP function for stripping HTML comments out of a string. It is useful when working with raw data, caching engines or data, extracted from another website. function...

Escaping single quotes in single-quoted Bash string - There are several cases where one would want to have single quote in single-quoted string. Several examples are:     - passing complex arguments to programs...

Running commands as System account in Windows - Windows System account is normally not available for the users. In some cases however one would want to run some command using System 's privileges for example when diagnozing permission...

Getting date and time in desired format in DOS/Windows cmd prompt - If you are familiar with Linux's date command and its pretty output formatting, you'll be surprised by the lack of even tiny bit of formatting in its DOS/Windows equivalent. However there's...

Several hints on writing CLI php scripts - Despite PHP is used mainly for web applications, it's a very handy language for writing command line applications too. Especially if you're used to, it can replace both bash and Perl for you. To...

Redirecting program input and output in Linux and Windows -   When working with console applications redirecting of program input and output is a must. It is used for piping one program's output to another's input, generating files with output for...

MIME type by file extension mapping - Below is a class for determining MIME type by file extension an vice verse. It's probably not full and not so accurate, but may come in handy in some cases. Sample usage for getting MIME type...

Add "Command prompt here" explorer menu item - It's very handy to be able to open command prompt right from the Explorer's context menu. This saves you opening the Start menu and then cd-ing manually to the desired location. Here's how to...

Fixing orphaned database users when migrating MSSQL database to different server - When database from one MSSQL server is migrated to another using detach -> copy -> attach you get into a funny situation: no server logins are created for database users and you cannot login...

PHP class for detecting and handling possible mail headers in text - Here's simple PHP class for detecting and handling possible mail headers in a string. It is useful for sanitizing input data from contact forms, guest books, etc. before sending it via email to...

Running remote rsync as root when root login is disabled - Rsync is widely used tool for incremental file transfer. It has several features that make it very attractive for easy to setup backup policy. You can run it over ssh to for additional...

Redirecting root's mail -     On most systems there are some cronjobs that run as root. Those jobs sent their output to root's mail file/folder. Here's an easy way to redirect those...

Restricting sftp users from opening ssh shells -   If you want to enable given user to manage his files over sftp, but you don't want him to execute commands on your system there's an easy way to do this. You...

Sending email with attachment from the command line - The following one-liner sends email with attachment straight from the command line: echo 'Here is the report from yesterday.' | uuencode /tmp/report.txt report-yesterday.txt | mail -s...

Few one-line commands on transferring files from one Linux computer to another - Few one-line commands on transferring files from one Linux computer to another We are considering tranfering multiple files on the network. Usual actions in this case are: cd...

Using ssh keys to setup automated secure backup exchange between two servers - In this article we'll cover setting up simple backups from server1 to backupserver . On server1 we create ssh public/private key pair with empty passphrase for root to be used to...

SSH access via PuTTY. Public/private key pair authentication - Lots of web hosting services offer SSH access. Most popular windows SSH client is PuTTY ( http://www.chiark.greenend.org.uk/~sgtatham/putty/ ). If you however have many different web hosting...

Installation of phpBB forum MySQL and non-latin character support - Here are a few steps to install phpBB without having the problem regarding wrong display of forum topics containing non-latin symbols. This happens, because phpBB converts those symbols in...

Bash script for encoding all files from a directory to different charset on a Linux box - This is a simple bash script which uses iconv binary to convert all the files in a given directory. Most common use - converting some website from local encoding to utf-8, for example...

Sending and receiving ICQ messages using PHP. Usage and application of PHP class WebIcqLite - In this articles we'll cover sending and receiving messages to/from ICQ users. This is a very useful way of communication with various applications. Lots of people have their ICQ client on for the...

Configuring static IP and DHCP on Windows - This article will cover a quick method to configure network connection under Windows. Let's say you have a lap-top computer that you use in two different places. The first one is with static...

Problem with .cer .crt files in Internet Information Server (IIS) 6 - If you have problem with .cer and .crt files in IIS there is a way to resolv him. IIS with ASP support try to execute .cer and .crt files with asp.dll. To rezolv this issue you...

Preventing SPAM. Obfuscating email addresses in HTML code - Everyone has encountered SPAM and knows how annoying is deleting 30-40 unsolicited email messages every day. On the other hand it appears that mass mailing is one of most successful advertising...

Changing root password and restoring mysql root user - This article addresses the questions "I accidently deleted MySQL's root account. What should I do?" and "I lost my root password! Help!". I suppose everyone has experienced...

Reading data from Excel files using PHP class Spreadsheet_Excel_Reader - If you have already read th article about generating Excel workbooks using PHP, this is an addition. Here's an example how to read these files. It is useful if you have large database and need...

Sending mails with PHPMailer. HTML content, inline images, attachments, SMTP, cyrillic support - PHPMailer is a PHP class for sending email. It has far more funtionality compared to the regular mail() function, including attachments and inline images. It is very usefull for actions like...

How to generate Excel file in cyrilic/cyrillic with Spreadsheet_Excel_Writer Pear package in PHP - This article explains how to generate Excel files with Spreadsheet_Excel_Writer Pear package in PHP. Installation To use this package, you should first install it: pear install...

How to protect and restrict access to a web directory using Apache web server - If you want to use the method described bellow, your Apache web server should have mod_auth and mod_access enabled. In the beginning If you have a directory in you website, which you want...

How to convert between utf8 and cp1251 without iconv - When you need convert some data from utf8 to cp1251(windows-1251) or cp1251 to utf8 you must use system function iconv. Frequently the hosting providers do not allow to use this function....

Simple configuration of BIND 9 - Hay, This is simple guide for configuration of bind, named, dns server and so... Let's go to install named(bind) from your linux distribution... There is one general configuration file:...

Two functions for trim() in javascript - Trim is one of the most common operations in any programming language. That's while it is implemented in almost all of them. I was amazaed that javascript doesn't provide this. Here are two...

How to send mail using telnet connection to SMTP server - 1. Open telnet session # telnet mail.server.tld 25 Trying mail.server.tld ... Connected to mail.server.tld Escape character is '^]'. 220 mail.server.tld ESMTP...

How to build an UTF-8 website with PHP and MySQL - Let's start with database creation. If you don't want to have difficulties with export/import operations, it is best to make it right. Here's a sample script: CREATE DATABASE baza_danni...

Configuring and installing Apache Web Server 2.0.x SSL - First: You need source of Apache 2.0.x Web Server from http://httpd.apache.org/download.cgi Second: You need distribution packets OpenSSL and OpenSSL-devel installed on your system # cd...

The best Real Blackhole Lists - The best RBL dns servers: cbl.abuseat.org, relays.ordb.org, list.dsbl.org, sbl.spamhaus.org, dnsbl.sorbs.net   Here are examples of configuration on Postfix and Qmail:...

Remove mail from postfix queue based on from email or rcpto email address - Here is a simple perl script to delete messages from postfix queue based on email #!/usr/bin/perl -w # # pfdel - deletes message containing specified address from # Postfix queue. Matches...

Useful links - Documentations PHP documentation (http://www.php.net/manual/en/) MySQL documentation (http://dev.mysql.com/doc/refman/4.1/en/index.html) pgSQL documentation...

Installing Apache web server with PHP module, MSSQL conectivity and Ioncube loader - If you ever wanted to install Apache web server with PHP and MSSQL support on Windows platform, you probably had a lot of problems. Here is a quick quide to save you a lot of time....

Qmail queue remover - #!/bin/bash echo "Qmail needs to be STOPPED!!!"; cd /var/qmail/queue/mess if [ "$1" == "" ] || [ "$1" == "help" ] || [ "$1"...

List of world countries in php array - $country_list = array( "Afghanistan", "Albania", "Algeria", "Andorra", "Angola", "Antigua and Barbuda",...

Issue with cyrilic texts with mysql and php - If you get all messy characters, try this after mysql_connect: $set = @mysql_query (\'SET NAMES CP1251\'); $set = @mysql_query (\'SET COLLATION_CONNECTION=CP1251_GENERAL_CI\');