22/08/2015 - LINUX
Uygulamanız için bir login kodu yazacağınıza, sadece .htaccess ve .htpasswd kullanarak bu işlemi gerçekleştirebilirsiniz. Daha fazla bilgi için, burayı ve burayı okuyabilirsiniz.
İstediğimiz şey:
user-1
link http://test.local/site-1
ile sadece site-1
kaynaklarına ulaşabilir.user-2
link http://test.local/site-2
ile sadece site-2
kaynaklarına ulaşabilir.hello
site-1
index.php
site-2
index.php
index.php
Bu link ile .htaccess dosyası ve bu link ile .htpasswd dosyası yaratabilirsiniz. Varsayalım ki projenin ana yolu /var/www/html/local/hello/
ve elimizdeki kullanıcılar user-1
ve user-2
. Yarattığımız dosyalar aşağıdaki gibi olmalılar.
Projenin ana yoluna gider.
AuthType Basic
AuthName "Protected Site"
AuthUserFile /var/www/html/local/hello/.htpasswd
Require valid-user
Projenin ana yoluna gider.
user-1:$apr1$CraA.0n7$JRqS7GyggMKNYcTP65rAW/
user-2:$apr1$2QIlucFc$auT3J0uJmBjhY0axRrVnJ.
Projenin site-1
klasörüne gider.
AuthUserFile /var/www/html/local/test/.htpasswd
Require user user-1
Projenin site-2
klasörüne gider.
AuthUserFile /var/www/html/local/test/.htpasswd
Require user user-2
inanzzz@inanzzz:/ $ sudo nano /etc/apache2/sites-available/hello.local.conf
# Config content
<VirtualHost *:80>
ServerName hello.local
ServerAlias www.hello.local
ServerAdmin admin@hello.local
DocumentRoot /var/www/html/local/hello
<Directory /var/www/html/local/hello>
AllowOverride AuthConfig
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/hello.local.error.log
CustomLog ${APACHE_LOG_DIR}/hello.local.access.log combined
</VirtualHost>
inanzzz@inanzzz:/ $ sudo a2ensite hello.local.conf
inanzzz@inanzzz:/ $ sudo nano /etc/hosts
# Hosts content
127.0.0.1 hello.local
inanzzz@inanzzz:/ $ sudo services apache2 restart
hello
site-1
index.php
.htaccess # user-1 specific one
site-2
index.php
.htaccess # user-2 specific one
index.php
.htaccess
.htpasswd
if (isset($_SERVER['PHP_AUTH_USER']) && in_array($_SERVER['PHP_AUTH_USER'], ['user-1', 'user-2'])) {
header('location: /'.substr($_SERVER['PHP_AUTH_USER'], -1));
exit;
}
Eğer http://hello.local
giderseniz, login bilgilerinizi girmeniz gerekecek. Girdiğiniz bilgilere göre, sadece ulaşım hakkına sahip olduğunuz klasör ve kaynaklara yönlendirilirsiniz. Diğer yerlere ulaşamazsınız.