Credit card encryption and storage

Despite the recomendations of PCI DSS for not storing the credit card data in database, you have to do this because on the client’s requirements. Its quite tough decision for the developer to choose the encryption method for the credit card data.

Based on my experience I came to this point that one should leave the encryption on the DBMS used. Most of the DBMSes are capable enough to provide the strong encryption. For example, MySQL provides functions AES_ENCRYPT and AES_DECRYPT which take a secret keyphrase and envcrypt the provided data.

My experince with PHP encryption using mcrypt extension and then savin in DB has not been so smooth as some times it works but some times you get squares and diamond shaped characters when decryption takes place.

Spliiting a Huge text or CSV file into smaller chunks

I got into a situation where i had to import a 10GB CSV file into mysql. I tried to open the file using excel, but it hanged and gave errors of Lesser Resources (RAM). 

Then I came to know about one less know tools of Linux shell called ‘csplit’.

I ran the command:

# csplit -k tenGB.csv +50000 {*}

-k = do not delete  the files on error encounter

+50000 = split to a new file after 49999 lines

{*} = repeat the same pattern on next files.

 

 

it created almost 43 files. with pattern xx00, xx01 and so on…

then i renamed all these files using the command:

#for f in *; do mv "$f" "${f%}.csv"; done

and thats it!!

Creating Apache Virtual hosts in windows vista

On my way to start Zend Framework development, I found that I have to create the virtual host in my windows vista machine. I Googled for this thing and finally got my virtual host ‘zf.local’ working with it document root set to ‘D:/htdocs/zf/public’ Directory (Usually, I create my document host D:/htdocs).

The steps needed to accomplish this task are listed below:

As I decided to have my virtual host name as ‘zf.local’, It was neccessary that I put an entry of the same domain the hosts file, otherwise my browser might have requested my ISP’s DNS server to locate ‘zf.local’. So what I did is I opened my hosts file which is located at ‘C:\windows\system32\drivers\etc\’  folder. I double clicked on that file, I added the line

127.0.0.1  zf.local

I pressed Ctrl+s to save. But to my surprise, notepad gave an error that the file is opened in read-only mode; so changes cannot be saved. What now??

Then the funda of vista permissions came to my mind and then I opened the notepad as administrator (see pic)

So, I opened the notepad as administrator and then browsed to my hosts file which was located at “c:\windows\system32\drivers\etc\” folder. When the file got loaded in the notepad, I added one entry for new hostname  as

127.0.0.1                    zf.local

Saved and quit the notepad. Till this time, I am ready with “http://zf.local” showing my localhost listing in apache. Next, its time to add the different document root for this server name. For this, I had to edit two files

  1. c:\amp\apache\conf\httpd.conf : in this file, the inclusion of vhosts file is commented by default. So I uncommented that line to become “Include conf/extra/httpd-vhosts.conf”
  2. c:\amp\apache\conf\extra\httpd-vhosts.conf : this is the actual file where we will add the virtual hosts entries. I opened the file and put the following para in it

NameVirtualHost 127.0.0.1

<VirtualHost 127.0.0.1>
ServerName localhost
DocumentRoot “d:/htdocs”
</VirtualHost>
<VirtualHost 127.0.0.1>
ServerName zf.local
ServerAdmin webmaster@dummy-host.localhost
DocumentRoot “d:/htdocs/zf/public”
</VirtualHost>

Saved the file and restarted my apache server. And that’s it, I am done.  When I browse “http://localhost”, I am getting the listing of localhost and when I am browsing “http://zf.local”, I am getting the spash screen of Zend Framework which means I am once again successful. :)

Remember that the first virtual host entry is quite important coz without it, “http://zf.local” will show you the zend framework splash screen only and you will never get the “http://localhost” listing.

Thanks to google :)

Keep PHPing

Am Zend Certified Engineer now!

Finally, after an experience of 4 years and hours of studying, I am a Zend Certified Engineer today. The exam is not as tough as I expected, at the same time its not an easy one.  For studying, I would recommend php|architect ZCE study guide. It covers all the topics, But the one book that helped me a in detail and advanced study in PHP5 unleashed from the author ‘John Coggeshall’. He has covered the more details that any book on PHP on the planet may have covered.

Its worth taking this exam as I learnt a lot new things about PHP now.

Find me on Zend yellow pages @ http://www.zend.com/en/store/education/certification/yellow-pages.php#show-ClientCandidateID=ZEND012882

Multiple attachments not going with PHPmailer v5

A bug in the PHPMailer v5 has been stopping me from sending multiple attachments in a mail. It was quite a confusing thing coz it I checked everything in my PHP code time and again. Somehow, after googling for this, i got my answer; it is actually a bug in PHPmailer v5.

This is how I recified the bug.

  1. Open the file class.phpmailer.php
  2. Goto line number 1236
  3. Change
    7=> 0
    to
    7=>count($this->attachment)
  4. Save the file and try.

Thanks for the contributors, it saved my time.

Planner 0.14.4 complete progress issue

I have been using the Planner for quite a long time. Its a very good software for Project Management and Planning. Over the time many improvements have been made in the project. The latest stable release you can find at http://live.gnome.org/planner is 0.14.4. I upgraded from 0.14.2 on my Vista Laptop. Everything is fine, however a strange thing I noted is that the complete progress of any task does not move beyond 75%. I tried on subtasks and individual tasks, but invain.

Finally, I consulted planner development team regarding this issue and Rhian Geleick guided me the temporary solution for the bug. The solution is

  1. Go to the installtaion directory of planner
    <INSTALL DIR>/share/planner/glade.
  2. Edit the file named ‘task-dialog.glade’ in this directory, in any of the text editors
  3. Goto Line number 236, and change
    <property name=”adjustment”>0 0 100 10 25 25</property>
    To
    <property name=”adjustment”>0 0 100 10 25 0</property>
  4. Anyone using the priority field should should also change line number 257
    From
    <property name=”adjustment”>0 0 9999 1 10 10</property>
    To
    <property name=”adjustment”>0 0 9999 1 10 0</property>
  5. Save the file and then Check in Planner. The bug is rectified.

Thanks for the Planner Team for their timely support.

Enable mod_rewrite in apache

If you are using Windows OS and want to enable mod_rewrite module here is how to do it.
This is the general configuration guideline both for Windows and Linux server:

QUOTE

1. Find the httpd.conf file (usually you will find it in a folder called conf, config or something along those lines)
2. Inside the httpd.conf file uncomment the line LoadModule rewrite_module modules/mod_rewrite.so (remove the pound ‘#’ sign from in front of the line)
3. Also find the line ClearModuleList is uncommented then find and make sure that the line AddModule mod_rewrite.c is not commented out.

For Windows, find the following section in httpd.conf file:


DocumentRoot "C:/path/to/my/root"

# Each directory to which Apache has access, can be configured with respect
# to which services and features are allowed and/or disabled in that
# directory (and its subdirectories).
#
# First, we configure the "default" to be a very restrictive set of
# permissions.
#

Now modify the option for AllowOverride to look like this:
<Directory />
Options All
AllowOverride All
</Directory>

Open rar file or Extract rar files under Linux or UNIX

download binary package from official rarlab site:
$ cd /tmp
$ wget http://www.rarlab.com/rar/rarlinux-3.6.0.tar.gz

Untar file
$ tar -zxvf rarlinux-3.6.0.tar.gz

Both unrar and rar commands are located in rar sub-directory. Just go to rar directory:
$ cd rar
$ ./unrar

Now copy rar and unrar to /bin directory:
# cp rar unrar /bin

How to use unrar

unrar command supports various options below are common options that you need to use everyday.

Task: To open rar (unpack) file in current directory type command:

$ unrar e file.rar

Please note that replace file.rar filename with your actual filename.

Task: List (l) file inside rar archive:

$ unrar l file.rar

Task: To extract (x) files with full path type command:

$ unrar x file.rar

(D) To test (t) integrity of archive, file type command:
$ unrar t file.rar