Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Mar 2004
    Posts
    95
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Password protection on a directory

    I want to password protect a directory and it's sub directories using .htaccess, but I also have some php scripts that need to access some files inside the protected directory. The access is using something like this 'require_once('functions.php');'

    But if I password protect the directory that functions.php is in, then access is denied to my php script. I tried adding a rule to allow the server's own IP to the .htaccess, but that didn't work. Can someone suggest some ways around this problem?

  • #2
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    I'm sure there must be an easier way than this, but can you not just add username and password to your require statement?
    PHP Code:
    require('http://user:pass@www.site.com/functions.php'); 
    I'm sure that probably isn't a great way to do it, but I think it would work. No idea how safe it is to do that either, I'm guessing probably not very?

  • Users who have thanked BluePanther for this post:

    Taipan (07-25-2011)

  • #3
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    If you are accessing it on the same server you won't need a password in your PHP script because it doesn't load the file with an HTTP request unless you explicitly ask it to with fopen wrappers(like in the previous post).


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •