2012-11-15 19 views
1

相關我以前的問題:.htaccess check for cookie first, then valid-userhttpd.conf代碼無法正常工作 - 建議?

嗨,大家好,我真的很感謝這裏的專家的一些幫助。我的httpd.conf應該要求用戶使用mod_auth_mysql或cookie來登錄 - 但現在它只是檢查用戶登錄。上一個問題的代碼現在位於我的httpd.conf中。

什麼工作:

目前,用戶都在/ var/WWW /下載和子目錄(在/ var/WWW /下載/〜名〜)需要使用mod_auth_mysql用戶名和密碼。這工作。

什麼是不工作:

的問題是:我應該需要設置要麼使用mod_auth_mysql(作品)登錄,一個cookie(不工作)。如果cookie存在,那麼當用戶轉到/ var/www/downloads /時,它應該自動顯示目錄的內容。但它不,它仍然要求用戶名/密碼。

我正在使用SetEnvIf,但它可能被錯誤地用於「滿足所有」。我可能會在httpd.conf和/ sites-enabled/000-default之間發生衝突。我對這裏的大部分內容都沒有經驗,所以任何幫助都會受到大力讚賞!

的httpd.conf:

RewriteEngine on 
RewriteLogLevel 9 
RewriteLog /var/www/logs/rewrite.log 

#Block IPs 
<Directory /var/www> 
    RewriteEngine On 

    #only use my server for apache 
    RewriteCond %{HTTP_HOST} !^2.2.2.2$ [NC] 
    RewriteRule ^(.*)$ http://www.google.co.uk/$1 [L,R=301] 

    RewriteCond %{REMOTE_ADDR} 0.0.0.0 [NC,OR] 
    RewriteCond %{REMOTE_ADDR} 1.1.1.1 [NC] 
    RewriteRule ^(.*)$ http://www.google.com [R] 
</Directory> 

# DOWNLOADS TOP DIRECTORY 
<Directory /var/www/downloads> 
    #Options Indexes 
    #AllowOverride All 
    #Order deny,allow 
    #Deny from all 
    #Allow from All 

    AuthName "Please don't hack the server, thanks" 
    AuthBasicAuthoritative Off 
    AuthUserFile /dev/null 
    AuthMySQL On 
    AuthType Basic 
    Auth_MYSQL on 
    Auth_MySQL_Host localhost 
    Auth_MySQL_User user 
    Auth_MySQL_Password password 
    AuthMySQL_DB db 
    AuthMySQL_Password_Table users 
    Auth_MySQL_Username_Field username 
    Auth_MySQL_Password_Field password 
    Auth_MySQL_Empty_Passwords Off 
    Auth_MySQL_Encryption_Types Plaintext 
    Auth_MySQL_Authoritative On 
    require user luke 

</Directory> 

# EXAMPLE USERS DIRECTORY 
# MIKE 
<Directory /var/www/downloads/mike> 
    SetEnvIf Cookie (.*)cookiename(.*) norequire_auth=yes 
    Order Deny,Allow 
    deny from all 
    Satisfy Any 

    #MYSQL AUTH 
    AuthName "Please login" 
    AuthBasicAuthoritative Off 
    AuthUserFile /dev/null 
    AuthMySQL On 
    AuthType Basic 
    Auth_MYSQL on 
    Auth_MySQL_Host localhost 
    Auth_MySQL_User user 
    Auth_MySQL_Password password 
    AuthMySQL_DB db 
    AuthMySQL_Password_Table users 
    Auth_MySQL_Username_Field username 
    Auth_MySQL_Password_Field password 
    Auth_MySQL_Empty_Passwords Off 
    Auth_MySQL_Encryption_Types Plaintext 
    Auth_MySQL_Authoritative On 
    require user mike 

    #COOKIE AUTH 
    Allow from env=norequire_auth 
</Directory> 

如果它可以幫助,/ 000默認啓用網站 - :可能會造成衝突? http://jsfiddle.net/Xcece/

我沒有使用.htaccess文件。我已經改變了大量的指令,並且已經完全喪失了。

我不能爲了我的生活找出它爲什麼不起作用 - 我不太瞭解可能存在的衝突,所以在正確的方向與解釋的一點,所以我可以避免在將來會這樣做很棒。謝謝。

+0

我試過註釋/完全刪除網站啓用/ 000默認內的所有指令,但這會停止一切正常工作,所以看起來像我堅持!繼續嘗試... – Jimbo

+0

相當希望我不必爲此付出代價(我的一半代表) - 我注意到在000-default中更改AllowOverride All並沒有改變任何東西。無法弄清爲什麼cookie檢測不起作用! – Jimbo

回答

1

終於!經過一個星期的搜索...

問題是與設置cookie。將文件放在不同的目錄中意味着httpd.conf中的cookie未被正確讀取 - 實際上正確的是

我必須將cookie的第四個參數設置爲'/ downloads/mike',從而允許它正確地被httpd.conf文件讀取。

session_start(); 
setcookie("cookiename","cookiename",time() + 3600, '/downloads/mike'); 

只記得銷燬使用time()-x使用第四個參數/downloads/mike摧毀它的cookie時。