PHP code example of jstnryan / slim-access-log
1. Go to this page and download the library: Download jstnryan/slim-access-log 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/ */
jstnryan / slim-access-log example snippets
ntiate the app
$settings = /get container reference
$container = $app->getContainer();
//PDO for writing to DB
$container['audit_database'] = function ($c) {
$pdo = new PDO("mysql:host=127.0.0.1;dbname=audit;charset=utf8", 'username', 'password');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
return $pdo;
};
//audit log middleware factory
$container['accessLog'] = function($c) {
$settings = [
'tableName' => 'accessLog',
'idColumn' => 'accessLogID',
'writeOnce' => false,
'custom' => [],
'captureResponse' => false,
'ignoredPaths' => [
'/exclude-all-paths/under-this-root',
],
];
return new \jstnryan\AccessLog\AccessLog($c->audit_database, $settings);
};
//attach middleware class
$app->add($app->getContainer()->get('accessLog'));
//more config, middleware, routes an' stuff here...
$app->run();