Archive for the ‘Notes’ Category

Original IP from behind a proxy

Thursday, November 1st, 2012

When you’re serving a page from behind a load balancer or a proxy of any kind, you may not get the user’s IP with the REMOTE_ADDR HTTP header. That may return the IP of the proxy. Instead, you may want to write a little IP checking function like the one in this Stackoverflow post.

Uploaded Excel mime type

Thursday, November 5th, 2009

I’ve been strugling to find the reason behind a malfunctioning Excel upload feature. The problem was that some times, the file would not have the application/vnd.ms-excel mime type. This was a bit of an issue, it was required for invaliding the type of the file.

By luck, a coworker discovered that the Excel file would return a different mime type if the Excel file was open in Excel when it was uploaded. Under these conditions, the mime type is application/octet-stream. In other words, when uploading an open Excel doc, Internet Explorer would have trouble identifying the file type and send along the generic mime-type application/octet-stream.

Bellow is a quick fix that should take care of future problems:

if (   $_FILES['excel_file']['type'] == 'application/vnd.ms-excel'
    || preg_match('/\\.xls$/', $_FILES['excel_file']['name']) ) {
    // continue working on the uploaded file...
}

Ubuntu in VirtualBox

Wednesday, October 21st, 2009

When installing Ubuntu (9.10) in Virtualbox (3.2.0), it’s important to check off the Enable PAE/NX option. Otherwise, powering off the machine will result in a broken boot sequence and an unusable virtual machine.

The option can be found in Settings > System > Processor.