a single file php library to manage users and roles on web site
easyauth.php - authentication library
login.php - form and code to login
logout.php - code to logout
setupandtest.php - test authentication, remove from production site
adminform.php - form and code to manage users and roles, should not be on production site!
authtest.php - file to check that you are authenticated or not
-
create mysql database or use existing one
-
copy easyauth.php,login.php,logout.php,settings.php.example,setupandtest.php to root of your php site
-
rename settings.php.example to settings.php and edit every line
-
Run setupandtest.php , this will create the tables and run a test on all the library functions
You now have 3 new tables in your database
easy_auth_prefix_user // 1 row for every user, should be empty after test
easy_auth_prefix_role // 1 row for every role, should have admin and guest
easy_auth_prefix_user_role // 1 row for every relation between the other 2 tables, should be empty after test
-
If the tests pass remove setupadntest.php from production env
-
add
require_once "easyauth.php";
to very top of php files that need authentication -
add to same file:
if(!isLoggedIn()){ header("location: login.php"); } else { $user_id = $_SESSION['easyauth'][$company_domain][$product_name]['id']; $username = $_SESSION['easyauth'][$company_domain][$product_name]['username']; }
you can copy adminform.php (temporarily) to site to create initial users, do not leave this file on production site!