barbushin / php-console

Handle PHP errors, dump variables, execute PHP code remotely in Google Chrome
https://chrome.google.com/webstore/detail/php-console/nfhmhhlpfleoednkpnnnkolmclajemef
MIT License
1.34k stars 283 forks source link

How to disable manually #124

Closed kzap closed 8 years ago

kzap commented 8 years ago

Password protection is nice but its basically telling everyone with PHPConsole that all it takes is a password and that we have the library

it would be nice if we could only activate the debugging via our own conditions like a COOKIE or some Admin Login.

Right now if you dont set a password, it assumes no password. I'd like to keep my debug code but show it to only those with access and not tell the world that we use PHPConsole on our site

kzap commented 8 years ago

ah nvm i see there's a Connector()->disable() method

https://github.com/barbushin/php-console/blob/07801c32ea32e4d57ddf1c6b9cf98ff7f2982542/src/PhpConsole/Connector.php#L180-L182

this works :)

//  ?phpconsole=1 to activate and ?phpconsole=0 to deactivate
if (isset($_GET['phpconsole']) && $_GET['phpconsole']) {
    $_SESSION['phpconsole'] = 1;
} elseif (isset($_GET['phpconsole']) && !$_GET['phpconsole'] && isset($_SESSION['phpconsole'])) {
    unset($_SESSION['phpconsole']);
}

// register this so all \PC::debug calls still work
\PhpConsole\Helper::register();
if (\PhpConsole\Connector::getInstance()->isActiveClient()) {
    $connector = \PhpConsole\Connector::getInstance();
    $connector->setPassword('YOUR PASSWORD'); // protect access by password
    $connector->enableSslOnlyMode(); // PHP Console clients will be always redirected to HTTPS
    if (!(isset($_SESSION['phpconsole']) && $_SESSION['phpconsole'])) {
        $connector->disable();
    } else {
        // Init errors & exceptions handler
        $handler = \PC::getHandler();
        $handler->start(); // start handling PHP errors & exceptions
    }
}
\PC::debug('test');