Redirect domain, add www

If you want to redirect your website’s visitors to your www domain name, add this in your apache virtualhost configuration

RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.com$
RewriteRule ^/(.*)$ http://www.domain.com/$1 [R=301,L]

and don’t forget to enable rewrite module

a2enmod rewrite

Redirect http to https

How to automatically redirect all your http request to your https website ?
Simply add this 3 lines in your http VirtualHost configuration

RewriteEngine on
RewriteCond %{HTTPS} !^on$ [NC]
RewriteRule . https://%{HTTP_HOST}%{REQUEST_URI}  [L]

Don’t forget to activate your rewrite module

a2enmod rewrite

php unzip no 1024 limit

Here, a simple script to unzip a .zip file in php without the 1024 characters limitations

function unzip($zip, $root, $target_folder = "") 
{
    $zip_file = zip_open($root . $zip);
    while ($zip = zip_read($zip_file))
    {
        $zip_object = zip_entry_name($zip);
        if (!is_dir(dirname($root . $target_folder . $zip_object))) 
        {
            mkdir(dirname($root . $target_folder . $zip_object), 0777, true);
        }
        $hedef_doc = $root . $target_folder . $zip_object;
        if(substr($hedef_doc, -1) != "/")
        {
            touch($hedef_doc);
            $target_file = fopen($hedef_doc, 'w');
            $size = 0;
            while($size < zip_entry_filesize($zip))
            {
                 fwrite($target_file, zip_entry_read($zip));
                 $size += 1024;
            }
     	     fclose($target_file);
        }
    }
    return true;
}

unzip("file.zip", "./", "target_directory");

IE blocking cookies in frames

For “security” reasons (stuff related to P3P Platform for Privacy Preferences), Internet Explorer does not accept cookies for a site inside a frame. But you can force him to accept cookies by adding this in your http header

PHP:

header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');

ASP.NET:

HttpContext.Current.Response.AddHeader("p3p","CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"");

Django:

response = render_to_response('mytemplate.html')
response["P3P"] = 'CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"'

JSP:

response.addHeader("P3P","CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"")