i have two classes Session and SupplierSession. SupplierSession is supposed to inherit from Session. how do i ensure that the session_start() in the __construct() method of Session does not get called in SupplierSession. here are the class definitions.

session.php

<?php
    class Session {
        private $loggedIn = false;
        public $userID;

        public function __construct() {
            session_start();
            $this->checkLogin();
        }

        public function isLoggedIn() {
            return $this->loggedIn;
        }

        public function login( $user ) {
            if ( $user ) {
                $this->userID = $_SESSION['userID'] = $user->userID;
                $this->loggedIn = true;
            }
        }

        public function logout() {
            unset( $this->userID );
            unset( $_SESSION['userID'] );
            $this->loggedIn = false;
        }

        private function checkLogin() {
            if ( isset( $_SESSION['userID'] ) ) {
                $this->userID = $_SESSION['userID'];
                $this->loggedIn = true;
            } else {
                unset( $this->userID );
                $this->loggedIn = false;
            }
        }
    }

    $session = new Session();
?>

suppliersession.php
<?php

    class SupplierSession extends Session {
        private $loggedIn = false;
        public $supplierID;

        public function __construct() {
            session_start();
            $this->checkLogin();
        }

        public function isLoggedIn() {
            return $this->loggedIn;
        }

        public function login( $supplier ) {
            if ( $supplier ) {
                $this->supplierID = $_SESSION['supplierID'] = $supplier->supplierID;
                $this->loggedIn = true;
            }
        }

        public function logout() {
            unset( $this->supplierID );
            unset( $_SESSION['supplierID'] );
            $this->loggedIn = false;
        }

        private function checkLogin() {
            if ( isset( $_SESSION['supplierID'] ) ) {
                $this->supplierID = $_SESSION['supplierID'];
                $this->loggedIn = true;
            } else {
                unset( $this->supplierID );
                $this->loggedIn = false;
            }
        }
    }

    $supplierSession = new SupplierSession();
?>

Session_start function is usually called in begning of page or from any common file which is included in all page in begning.

Take out it from classes

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.