Skip to content

tigoCaval/login-session

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Login Session

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();
Method Description
validate() This method is responsible for validating the login.
auth() On a private page where the user must be logged in, you can use this method in the page controller or on the page itself.
logout() Use this method to destroy session or logout.
user() Use this method to collect session information.

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