Secure php-writable directories

Although, it’s ideal to save cache outside the document root/web root directory, often you are forced to use a directory within document root. In such a case use the following method to safeguard the folder.

Find the apache user:
ps axo user,group,comm | grep httpd

Typically, this would output something like below (It may show group id on Macs).
terminal screenshot

Make this user to own cache or any other folder to which PHP has to write.
chown -R apache:apache cache/

Set permissions to 700 or 755 never  a 777!
chmod 700 cache/

Fix for Duplicate Headers Error 349


This error was bugging me whole of last week. This error is specific to Google Chrome. Not a bug in chrome itself though, as other browsers ignore duplicate headers, this seems like an issue with Chrome. This can be addressed easily the following ways, if you or your web app is sending out headers.

1. Enclose filename using “”. i.e

header('Content-Disposition: attachment; filename="'.$file_name.'"');

instead of

header('Content-Disposition: attachment; filename='.$file_name);

2. If possible replace spaces and commas (,) with underscores (_)

$file_name = str_replace(array('"', "'", ' ', ','), '_', $file_name);

3. Explicitly tell PHP to override headers by setting optional replace parameter to true.

header('Content-type: application/pdf', true);

Rajnikanth’s new fan page

RAJANIKANTHRajnikanth, the name that could make titles feel proud, has a new type of fan page. It’s as simple as rajni and equally magical! It works only after you unplug yourself from the internet! How you do that is left to you, but sir’s site has a quick help if you want 😉 Come on da, it’s sir, he knows everything, it’s internet which is trying to understand him!

Having Firebug installed on my browser, you think I’ll keep away from cracking sir’s website?! Yes, I did. The main flash keeps pinging a xml file. When not found, either net is down or you are off the internet! So assumes the app.

Anyways, here’s what the config.xml has. Love the attitude of this website!

All about rajnikanth.

What?! Sir won’t excuse you for attempting to crack his site. Here’s is what happened to Firebug.

BTW, you can experience it here:

Extending ls command

How to generate list of files and their size in bytes?

Comma Separated List (CSV)
$ ls -l | awk '{ print $5 "," $9 }' > list.csv

Tab Separated List (TSV)
$ ls -l | awk '{ print $5 "\t" $9 }' > list.tsv

$5 – Ordinal position for Size in bytes.
$9 – Name of the file.

Get a count of files/folders in the current directory
$ ls -l | wc -l