本文整理匯總了PHP中Piwik\Filesystem::createHtAccess方法的典型用法代碼示例。如果您正苦於以下問題:PHP Filesystem::createHtAccess方法的具體用法?PHP Filesystem::createHtAccess怎麽用?PHP Filesystem::createHtAccess使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Piwik\Filesystem
的用法示例。
在下文中一共展示了Filesystem::createHtAccess方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: createHtAccessFiles
/**
* Generate Apache .htaccess files to restrict access
*/
public static function createHtAccessFiles()
{
// deny access to these folders
$directoriesToProtect = array('/config', '/core', '/lang', '/tmp');
foreach ($directoriesToProtect as $directoryToProtect) {
Filesystem::createHtAccess(PIWIK_INCLUDE_PATH . $directoryToProtect, $overwrite = true);
}
// Allow/Deny lives in different modules depending on the Apache version
$allow = "<IfModule mod_access.c>\nAllow from all\n</IfModule>\n<IfModule !mod_access_compat>\n<IfModule mod_authz_host.c>\nAllow from all\n</IfModule>\n</IfModule>\n<IfModule mod_access_compat>\nAllow from all\n</IfModule>\n";
$deny = "<IfModule mod_access.c>\nDeny from all\n</IfModule>\n<IfModule !mod_access_compat>\n<IfModule mod_authz_host.c>\nDeny from all\n</IfModule>\n</IfModule>\n<IfModule mod_access_compat>\nDeny from all\n</IfModule>\n";
// more selective allow/deny filters
$allowAny = "<Files \"*\">\n" . $allow . "Satisfy any\n</Files>\n";
$allowStaticAssets = "<Files ~ \"\\.(test\\.php|gif|ico|jpg|png|svg|js|css|swf)\$\">\n" . $allow . "Satisfy any\n</Files>\n";
$denyDirectPhp = "<Files ~ \"\\.(php|php4|php5|inc|tpl|in|twig)\$\">\n" . $deny . "</Files>\n";
$directoriesToProtect = array('/js' => $allowAny, '/libs' => $denyDirectPhp . $allowStaticAssets, '/vendor' => $denyDirectPhp . $allowStaticAssets, '/plugins' => $denyDirectPhp . $allowStaticAssets, '/misc/user' => $denyDirectPhp . $allowStaticAssets);
foreach ($directoriesToProtect as $directoryToProtect => $content) {
Filesystem::createHtAccess(PIWIK_INCLUDE_PATH . $directoryToProtect, $overwrite = true, $content);
}
}