Skip to content

godzilla/php-easy-auth

Repository files navigation

php-easy-auth

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

steps to install

  1. create mysql database or use existing one

  2. copy easyauth.php,login.php,logout.php,settings.php.example,setupandtest.php to root of your php site

  3. rename settings.php.example to settings.php and edit every line

  4. 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

  1. If the tests pass remove setupadntest.php from production env

  2. add require_once "easyauth.php"; to very top of php files that need authentication

  3. 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!

About

a single file php library to manage users and roles on web site

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages