SartajPHP ( PHP Framework )


Secure Your Website

Secure Your Website

We need to secure our website. Here I explain how you secure your website with in SartajPHP. Put the code onstart event of application. SartajPHP application understand you as GUEST when you are not login. After the login your type is defined by application developer.

class login extends \Sphp\tools\BasicApp {

    private $mainhome = null;
    private $showhome = null;

    public function onstart() {

        // this application can access by ADMIN or GUEST, if you something else then it will call getWelcome function from comp.php file
        $this->getAuthenticate("ADMIN,GUEST");

    }

    public function page_event_login($evtp){

        // any function get record from database

        $row = $this->getRow($evtp);

         if(!getCheckErr()) {
             $this->Client->session('admin-name', $row['name']);
             //setSession with Authenticate type ADMIN, you can give anything isn't fix
           // you have full power to design any type of authentication system
             setSession('ADMIN', $row['id']);
             getWelcome();
        }else {
            setErr('app', 'Invalid User or Password' );
            $this->setTempFile($this->mainhome);
        }

    }    

    public function page_event_logout($param) {
        destSession();

        $this->page->forward(getAppPath("index"));
   }

}

comp.php file getWelcome Function for froward to  creect url

function getWelcome() {
    $page = SphpBase::page();
    $logType = SphpBase::page()->getAuthenticateType();

    switch ($logType) {

        case "ADMIN": {
                $page->forward(getAppPath("admhome", '', '', true));
                break;
            }

        case "MEMBER": {
                $page->forward(getAppPath("mebhome", '', '', true));
                break;
            }

        default: {
                $page->forward(getAppPath("index"));
                break;
            }
    }
}