index.php

$admin_cookie_code="1234567890";
setcookie("JoomlaAdminSession",$admin_cookie_code,0,"/");
header("Location: /administrator/index.php");

.htaccess文件
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/administrator
RewriteCond %{HTTP_COOKIE} !JoomlaAdminSession=1234567890
RewriteRule .* - [L,F]

我使用了此代码,但无法正常工作...
页面将重定向到管理员,但也可以访问www.domain.com/administrator

最佳答案

我已经厌倦了为此问题寻找答案,只是制作了一个PHP代码,如果访问者在没有安全密钥或未注册用户的情况下进入/ administration文件夹,它将重定向

只需将此代码放在“echo”指令之前的管理文件夹(/administration/index.php)的index.php文件末尾:

/* Block access to administrator
 --------------------------------------------- */
$user =& JFactory::getUser();
$secretkey = 'mysecretkey';
$redirectto = 'location: http://www.mysite.com';
$usertype = 'Registered';

//Check if the user is not logged in or if is not a super user:
if ($user->guest || (!$user->guest && $user->usertype != $usertype) ) {
 //Check if the secret key is present on the url:
 if (@$_GET['access'] != $secretkey) { header($redirectto); }
}
/* --------------------------------------------- */

之后,您将只能使用以下方法访问您的网站:
www.mysite.com/administrator/?access=mysecretkey

在Joomla 1.5和Jooma 2.5上进行了测试,两者都效果很好。

我在页面上对此进行了更多解释:
http://developer.infoymas.com/jooma/protect-your-joomla-administrator-folder/

09-10 07:33
查看更多