JavaScript – Confirm Before Window is Closed

Here is the JavaScript code:
1
2
3
4
5
6
7
8
9
10
/** Confirms when closing the window **/
function checkClose()
{
    $("#s_scan_number").focus();
    return "Please DON'T close the window. Use the form button on the bottom.";
}
window.onbeforeunload = checkClose;
 
//to remove the confirmation dynamically:
window.onbeforeunload = null;

SVN Ignore Files or Directory

This is a small command that will ignore some files or directory in SVN. Ignoring files is useful when there are files that are not actually needed by your project but it just get in there like temporary files, cache files and log files. You may also need to ignore files that are created by the operating system or some programs.
For example, you wanted to ignore the annoying Thumbs.db in Windows. Thumbs.db usually appears on a directory when it is viewed in Thumbnail view. To ignore Thumbs.db in project/images, here are the possible commands:
1
2
cd project/images
svn propedit svn:ignore Thumbs.db .
First, we change current directory to the images directory. Next, we ignore the file Thumbs.db and set that property to “.”, which means the current directory. If that gives you error that says that Thumbs.db is not a working copy sort of, change the command into this:
1
svn propset svn:ignore Thumbs.db .
The above command will ignore that file which is not yet added to the repository. If you wanted to ignore a directory, the command is the same as ignoring files.
Another classic example is to ignore files inside the templates_c directory used by Smaty template cache. Here is it (be sure to change into the templates_c directory):
1
2
svn propset svn:ignore *.php .
svn commit -m "Ignored smarty cache"
Or you can use propedit just in case you have already added them to the repository. If you are using a GUI based SVN client, it is much easier.

Using Basic access authentication HTTP Auth With PHP

How to set up your App in a way that the browser prompts for username/password.


Problem

You probably don't want the whole world to see your development in progress. So you want to restrict access to a fortunate few using HTTP (basic) auth. In the fortrabbit PHP/FPM infrastructure neither PHP_AUTH_USER nor PHP_AUTH_PW are available - but you can hack around easily.


Solution

To utilize HTTP (basic) Auth, you need to add a directive in your .htaccess file, forwarding the Authorization header as an environment variable. This variable then contains the base64 encoded authentication data, which you can then decode to the PHP_AUTH_USER and PHP_AUTH_PW.

Modify .htaccess file


RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]


Decode auth header in PHP


// header was not provided

if (empty($_SERVER['REMOTE_USER'])) {
    header('WWW-Authenticate: Basic realm="My Realm"');
    header('HTTP/1.0 401 Unauthorized');
    echo 'Need auth!';
    exit;
}

// extract user and pw from encoded auth data
list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = explode(
    ':',
    base64_decode(substr($_SERVER['REMOTE_USER'], 6))
);