src/Session.php
protected function startOrRestart()
    {
        // if we have an active session: stop here
        if ( session_status() == PHP_SESSION_ACTIVE )
            return;

        // set the session dir if needed
        if ( $this->SessionDir )
        {
            if ( !file_exists( $this->SessionDir ) )
            {
                mkdir( $this->SessionDir, 0777, true );
            }
            session_save_path( $this->SessionDir );
        }

        // start the session
        session_start();

        // check ip and browser info first
        $FingerPrint = "";
        if ( $this->IpAddress )
        {
            if ( !$this->IpAddress->isValid() )
            {
                session_unset();
                session_destroy();
                throw new \Exception(
                        "Cannot start session. Reason: Invalid IP " . $this->IpAddress->getValue() . " detected", 403 );
            }
            else
                $FingerPrint = $this->IpAddress->getValue();
        }

        if ( $this->Browser )
        {
            if ( !$this->Browser->isKnownBrowser() )
            {
                session_unset();
                session_destroy();
                throw new \Exception(
                        "Cannot start session. Reason: Invalid Browser " . $this->Browser->getSignature() . " detected.", 403 );
            }
            else
                $FingerPrint .= $this->Browser->getSignature();
        }

        // now check for changes if we had a session before or a timeout
        $currFp = md5( $FingerPrint );
        $prevFp = isset( $_SESSION[ "FingerPrint" ] ) ? $_SESSION[ "FingerPrint" ] : null;
        if ( $prevFp )
        {
            if ( $prevFp != $currFp )
            {
                session_unset();
                session_destroy();
                throw new \Exception( "Cannot start session. Reason: IP changed. Current is $currFp, previous was: $prevFp", Interfaces\HttpResponder::EXIT_CODE_UNAUTHORIZED );
            }
        }

        // check timeout
        $currTime    = time();
        $prevTime    = isset( $_SESSION[ "LastSessionStart" ] ) ? $_SESSION[ "LastSessionStart" ] : null;
        $timeOutSecs = isset( $_SESSION[ "TimeOutSecs" ] ) ? $_SESSION[ "TimeOutSecs" ] : null;
        if ( $prevTime && $timeOutSecs )
        {
            if ( $prevTime + $timeOutSecs < $currTime )
            {
                session_unset();
                session_destroy();
                throw new \Exception( "Session timeout", Interfaces\HttpResponder::EXIT_CODE_UNAUTHORIZED );
            }
        }

        $_SESSION[ "FingerPrint" ]      = $currFp;
        $_SESSION[ "LastSessionStart" ] = $currTime;
    }
protected function startOrRestart()
    {
        // if we have an active session: stop here
        if ( session_status() == PHP_SESSION_ACTIVE )
            return;

        // set the session dir if needed
        if ( $this->SessionDir )
        {
            if ( !file_exists( $this->SessionDir ) )
            {
                mkdir( $this->SessionDir, 0777, true );
            }
            session_save_path( $this->SessionDir );
        }

        // start the session
        session_start();

        // check ip and browser info first
        $FingerPrint = "";
        if ( $this->IpAddress )
        {
            if ( !$this->IpAddress->isValid() )
            {
                session_unset();
                session_destroy();
                throw new \Exception(
                        "Cannot start session. Reason: Invalid IP " . $this->IpAddress->getValue() . " detected", 403 );
            }
            else
                $FingerPrint = $this->IpAddress->getValue();
        }

        if ( $this->Browser )
        {
            if ( !$this->Browser->isKnownBrowser() )
            {
                session_unset();
                session_destroy();
                throw new \Exception(
                        "Cannot start session. Reason: Invalid Browser " . $this->Browser->getSignature() . " detected.", 403 );
            }
            else
                $FingerPrint .= $this->Browser->getSignature();
        }

        // now check for changes if we had a session before or a timeout
        $currFp = md5( $FingerPrint );
        $prevFp = isset( $_SESSION[ "FingerPrint" ] ) ? $_SESSION[ "FingerPrint" ] : null;
        if ( $prevFp )
        {
            if ( $prevFp != $currFp )
            {
                session_unset();
                session_destroy();
                throw new \Exception( "Cannot start session. Reason: IP changed. Current is $currFp, previous was: $prevFp", Interfaces\HttpResponder::EXIT_CODE_UNAUTHORIZED );
            }
        }

        // check timeout
        $currTime    = time();
        $prevTime    = isset( $_SESSION[ "LastSessionStart" ] ) ? $_SESSION[ "LastSessionStart" ] : null;
        $timeOutSecs = isset( $_SESSION[ "TimeOutSecs" ] ) ? $_SESSION[ "TimeOutSecs" ] : null;
        if ( $prevTime && $timeOutSecs )
        {
            if ( $prevTime + $timeOutSecs < $currTime )
            {
                session_unset();
                session_destroy();
                throw new \Exception( "Session timeout", Interfaces\HttpResponder::EXIT_CODE_UNAUTHORIZED );
            }
        }

        $_SESSION[ "FingerPrint" ]      = $currFp;
        $_SESSION[ "LastSessionStart" ] = $currTime;
    }
will start a new session OR