When redirecting from HTTPS -> HTTP and replacing the url with a HTTPS version, also take DIR_WS_HTTPS_CATALOG into consideration (bug #492)
Close/Write the session data before exiting
Replace mysql_* with mysqli_* for PHP 5.5 compatibility