PHP code example of district5 / php-postman-detect
1. Go to this page and download the library: Download district5/php-postman-detect library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
district5 / php-postman-detect example snippets
$_SERVER['HTTP_USER_AGENT'] = 'PostmanRuntime/7.26.8';
\District5\PostmanDetect\PostmanDetector::isPostman(); // true
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko)';
\District5\PostmanDetect\PostmanDetector::isPostman(); // false
$_SERVER['HTTP_USER_AGENT'] = 'PostmanRuntime/7.26.8';
// Disallow this endpoint with Postman always
\District5\PostmanDetect\PostmanDetector::disallowAlways(); // throws exception
// Current environment is 'local'
// disallow on production
\District5\PostmanDetect\PostmanDetector::disallowOnEnvs('local', ['prod']); // no exception
// disallow on production and staging
\District5\PostmanDetect\PostmanDetector::disallowOnEnvs('local', ['prod', 'staging']); // no exception
// Current environment is 'prod'
// disallow on production
\District5\PostmanDetect\PostmanDetector::disallowOnEnvs('prod', ['prod']); // throws exception
// disallow on production and staging
\District5\PostmanDetect\PostmanDetector::disallowOnEnvs('prod', ['prod', 'staging']); // throws exception
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.