Catching All HTTP Requests to Apache and Storing Them in DB


Good morning everyone!

I was just looking to pick everyone’s mind on something I would like to do…

So, Apache has it’s access log already which essentially already does most of what I want but it stores it in a flat file that is always large and even if it isn’t it still doesn’t provide me with everything I want to be able to do.

I would like to be able to store all of that type of information (url requests whether coming from front-end ajax or a backend script and any parameters within the URL) and the user_id that is stored within a $_SESSION.

Does anyone have any thoughts on how this could be accomplished? I built this little function just for testing purposes:

function log_uri ( $pdo ) {

//check that user is set
if ( isset ( $_SESSION[‘user_id’] ) ) {

$query = ‘
INSERT INTO log_uri (user_id, uri) VALUES (:user_id, :page)
$statement = $pdo->prepare($query);
‘:user_id’ => $_SESSION[‘user_id’],
‘:page’ => $_SERVER[‘REQUEST_URI’],



But, it does not do what I want. Mainly, because it is only catching backend requests and not any of multiple AJAX requests that are happening very often and are of more interest to me than the back end requests. Here is what it a sample of what it captures so far:

Any thoughts? Maybe there is a way to detect any ajax response or something? Or maybe I can modify the Apache logging system to go into a database and hopefully pick up the user_id?