开发者

apache basic authentication without the ugly popup?

开发者 https://www.devze.com 2023-02-25 04:49 出处:网络
I like using .htaccess to 开发者_如何学运维password protect a directory, especially since it recursively protects all subdirectories as well. However, I despise the ugly login popup you get everytime.

I like using .htaccess to 开发者_如何学运维password protect a directory, especially since it recursively protects all subdirectories as well. However, I despise the ugly login popup you get everytime. Instead of using basic auth I'd like to use mod_rewrite (or similar) to password protect a directory (and all subdirectories) but have a simple html login for powered by php instead.

Ideas?


no... there is no way to use "basic authentication" with custom forms since this is done completely by the browser.


There is a workaround by sending an AJAX request (which works JS-internally and does not popup a window) from a form:

  $.ajax({
     type: 'POST',
     url: 'login.php'
     username: $('input#user').value,    // form fields
     password: $('input#pw').value,
  });

The browser keeps the credentials cached for subsequent, normal GET requests.

(Logging out from a HTTP auth is significantly more complex.)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号