tigo/login-session

v0.0.1 2021-08-02 21:33 UTC

This package is auto-updated.

Last update: 2024-09-29 06:08:57 UTC


README

Creating session for login in PHP

  • MIT license. Feel free to use this project. Leave a star ⭐ !
  • Download package: composer require tigo/login-session

If you found this project useful, consider making a donation to support the developer.

paypal | paypal

Introduction

Somewhere in your project, you may need to use autoload

include __DIR__ ."/vendor/autoload.php";

Example

  • Configuration:
 In the src/config/Standard.php directory
  • In the Standard class there is a method called postLogin(), it is through it that you will implement your logic.
  • By default the postLogin() method has an implemented logic which receives data from an array, to perform post validation
// the function must return a boolean value.
public function postLogin() 
{
       $user = isset($_POST[self::USER]) ? $_POST[self::USER] : false;
       $pw =   isset($_POST[self::PW]) ? md5($_POST[self::PW]) : false; 
       $table = TestMatrix::table();
       foreach ($table as $key => $item) {

            if($user == $item->user && $pw == $item->password){
               $_SESSION[self::SESSION] = $_POST[self::USER];
               return true;
            }
       }
       return false;
  }

Method TestMatrix::table()

  public static function table() 
  {
      return [
          1=> (object) ["user"=>"admin","password"=>md5("123")],
          2=> (object) ["user"=>"admin2","password"=>md5("1234")],
          3=> (object) ["user"=>"admin3","password"=>md5("12345")]
      ];
  }

Example methods

use Tigo\LoginSession\Login; // import class
$login = new Login();
$login->validate();

Problems

If you discover any issues, please contact my email or issue tracker and post the details.

Contributors

License

MIT license. See the archive License