Hey

I've created a .htaccess file as below:

AuthType Basic
AuthName "Homepage Login"
AuthUserFile /path-to-htpasswd/.htpasswd
require valid-user

& the .htpasswd file as below:

username1:pass
username2:pass

The files work perfectly at passwording the directory. The next file in the directory is then: index.php . I'd like to know how to retrieve the variables set for the username & the password from the .htaccess file. So I can do something like the below:

index.php

<body>
<?php
include "include.php";
accountcheck($username, password)
echo "Welcome $username, you are now logged into your account: $account[name]!";

?>

That's just a small example but I am trying to retrieve the variables that you input into the password box. Can anyone please help?

    you can use getenv("REMOTE_USER"); to retrieve the username, looking at the environment variables specification is doesn't mention how to get password (for security its proably not possible).
    But why not instead of using a htaccess file to authenticate users, use mysql to authenticate users. Its fairly simple to do I have an example script i could give you. or if you don't have access to mysql (or postgres, mssql etc.) you could just use text file database.
    (the mysql is probably safer and more secure and not too difficult)

      I already have it setup to do mysql authentification aswell. But people can still view the contents of the folder which is what I'm trying to avoid. Thank-you for your reply, can anyone else help?

        Just another thing, I've seen this done on other sites like on my phpmyadmin for my site:

        http://www.uklinux.net/s1phpmyadmin/

        entering the name & pass for your database opens it. This link enables you to manage many different databases & each username/password takes you to the database you require.

          lol ok, to even access the directory you need to enter the name. So thanks for the REMOTE_USER thing. I can use that to determine the user & the password will be in the .htpasswd file anyway. A seperate script can be made to change this if I need but I don't need to check the password. 🙂

            Write a Reply...