Log GET requests and querystring in PHP (Apache)
We have a PHP application running on Apache and want to log all API requests (GET + parameters).
I have seen this post Best way to log POST data in Apache? where it says "the GET requests will be easy, because they will be in the apache log".
However, when I look in our logs, they are not there. What server log settings do I need to have to record GET requests + querystring? No mention of how to do this in https://httpd.apache.org/docs/2.4/logs.html
php apache api logging get
add a comment |
We have a PHP application running on Apache and want to log all API requests (GET + parameters).
I have seen this post Best way to log POST data in Apache? where it says "the GET requests will be easy, because they will be in the apache log".
However, when I look in our logs, they are not there. What server log settings do I need to have to record GET requests + querystring? No mention of how to do this in https://httpd.apache.org/docs/2.4/logs.html
php apache api logging get
From the Apache Documentation -> Access log: "The server access log records all requests processed by the server." It explicitly contains an example where a GET request is logged (paragraph 8) Maybe you could compare the settings explained there with yours to see if your server logs incoming requests
– akraf
Jan 2 at 14:29
add a comment |
We have a PHP application running on Apache and want to log all API requests (GET + parameters).
I have seen this post Best way to log POST data in Apache? where it says "the GET requests will be easy, because they will be in the apache log".
However, when I look in our logs, they are not there. What server log settings do I need to have to record GET requests + querystring? No mention of how to do this in https://httpd.apache.org/docs/2.4/logs.html
php apache api logging get
We have a PHP application running on Apache and want to log all API requests (GET + parameters).
I have seen this post Best way to log POST data in Apache? where it says "the GET requests will be easy, because they will be in the apache log".
However, when I look in our logs, they are not there. What server log settings do I need to have to record GET requests + querystring? No mention of how to do this in https://httpd.apache.org/docs/2.4/logs.html
php apache api logging get
php apache api logging get
asked Jan 2 at 14:24
JamesJames
4391416
4391416
From the Apache Documentation -> Access log: "The server access log records all requests processed by the server." It explicitly contains an example where a GET request is logged (paragraph 8) Maybe you could compare the settings explained there with yours to see if your server logs incoming requests
– akraf
Jan 2 at 14:29
add a comment |
From the Apache Documentation -> Access log: "The server access log records all requests processed by the server." It explicitly contains an example where a GET request is logged (paragraph 8) Maybe you could compare the settings explained there with yours to see if your server logs incoming requests
– akraf
Jan 2 at 14:29
From the Apache Documentation -> Access log: "The server access log records all requests processed by the server." It explicitly contains an example where a GET request is logged (paragraph 8) Maybe you could compare the settings explained there with yours to see if your server logs incoming requests
– akraf
Jan 2 at 14:29
From the Apache Documentation -> Access log: "The server access log records all requests processed by the server." It explicitly contains an example where a GET request is logged (paragraph 8) Maybe you could compare the settings explained there with yours to see if your server logs incoming requests
– akraf
Jan 2 at 14:29
add a comment |
1 Answer
1
active
oldest
votes
The GET request are logged in the access log file. Read the documentation you provided, especially the Access Log
part is important.
Your Apache host should be configured with something like:
LogLevel info
ErrorLog "/private/var/log/apache2/{hostname}-error.log"
CustomLog "/private/var/log/apache2/{hostname}-access.log" combined
GET requests can then be found in /private/var/log/apache2/{hostname}-access.log
An easy and quick way to do this for debugging purposes is to write a function that logs the POST data.
function logPost() {
if (isset($_POST && !empty($_POST) {
foreach($_POST as $key => $value) {
error_log('=== _POST REQUEST ===');
error_log('_POST: '.$key.' => '.$value);
}
// OR serialise the data but this is less readable
error_log('=== _POST REQUEST ===');
error_log(serialise($_POST));
}
}
POST requests can then be found in /private/var/log/apache2/{hostname}-error.log
Just to be clear, do you replace {hostname} with the hostname or is it a variable that is automatically replaced.
– James
Jan 3 at 11:04
Yes manually replace it with your hostname or use an ENV variable with the name if you have one
– G4Hu
Jan 3 at 11:07
Just to be clear and I may have to rewrite the question - I am looking to log GET requests made to another server NOT GET requests on this server. Will this still work?
– James
Jan 3 at 11:09
Ah, that would have been good to make more clear in the question. Apache can only log requests made TO it, not from it. At least as far a i know
– G4Hu
Jan 3 at 11:20
If you where to query your own serverhttp://host.example/index.php?query=test_api
this would be logged by Apache. If you make a request from inside phpheader(...)
for example, that will not be logged
– G4Hu
Jan 3 at 11:24
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54008051%2flog-get-requests-and-querystring-in-php-apache%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The GET request are logged in the access log file. Read the documentation you provided, especially the Access Log
part is important.
Your Apache host should be configured with something like:
LogLevel info
ErrorLog "/private/var/log/apache2/{hostname}-error.log"
CustomLog "/private/var/log/apache2/{hostname}-access.log" combined
GET requests can then be found in /private/var/log/apache2/{hostname}-access.log
An easy and quick way to do this for debugging purposes is to write a function that logs the POST data.
function logPost() {
if (isset($_POST && !empty($_POST) {
foreach($_POST as $key => $value) {
error_log('=== _POST REQUEST ===');
error_log('_POST: '.$key.' => '.$value);
}
// OR serialise the data but this is less readable
error_log('=== _POST REQUEST ===');
error_log(serialise($_POST));
}
}
POST requests can then be found in /private/var/log/apache2/{hostname}-error.log
Just to be clear, do you replace {hostname} with the hostname or is it a variable that is automatically replaced.
– James
Jan 3 at 11:04
Yes manually replace it with your hostname or use an ENV variable with the name if you have one
– G4Hu
Jan 3 at 11:07
Just to be clear and I may have to rewrite the question - I am looking to log GET requests made to another server NOT GET requests on this server. Will this still work?
– James
Jan 3 at 11:09
Ah, that would have been good to make more clear in the question. Apache can only log requests made TO it, not from it. At least as far a i know
– G4Hu
Jan 3 at 11:20
If you where to query your own serverhttp://host.example/index.php?query=test_api
this would be logged by Apache. If you make a request from inside phpheader(...)
for example, that will not be logged
– G4Hu
Jan 3 at 11:24
add a comment |
The GET request are logged in the access log file. Read the documentation you provided, especially the Access Log
part is important.
Your Apache host should be configured with something like:
LogLevel info
ErrorLog "/private/var/log/apache2/{hostname}-error.log"
CustomLog "/private/var/log/apache2/{hostname}-access.log" combined
GET requests can then be found in /private/var/log/apache2/{hostname}-access.log
An easy and quick way to do this for debugging purposes is to write a function that logs the POST data.
function logPost() {
if (isset($_POST && !empty($_POST) {
foreach($_POST as $key => $value) {
error_log('=== _POST REQUEST ===');
error_log('_POST: '.$key.' => '.$value);
}
// OR serialise the data but this is less readable
error_log('=== _POST REQUEST ===');
error_log(serialise($_POST));
}
}
POST requests can then be found in /private/var/log/apache2/{hostname}-error.log
Just to be clear, do you replace {hostname} with the hostname or is it a variable that is automatically replaced.
– James
Jan 3 at 11:04
Yes manually replace it with your hostname or use an ENV variable with the name if you have one
– G4Hu
Jan 3 at 11:07
Just to be clear and I may have to rewrite the question - I am looking to log GET requests made to another server NOT GET requests on this server. Will this still work?
– James
Jan 3 at 11:09
Ah, that would have been good to make more clear in the question. Apache can only log requests made TO it, not from it. At least as far a i know
– G4Hu
Jan 3 at 11:20
If you where to query your own serverhttp://host.example/index.php?query=test_api
this would be logged by Apache. If you make a request from inside phpheader(...)
for example, that will not be logged
– G4Hu
Jan 3 at 11:24
add a comment |
The GET request are logged in the access log file. Read the documentation you provided, especially the Access Log
part is important.
Your Apache host should be configured with something like:
LogLevel info
ErrorLog "/private/var/log/apache2/{hostname}-error.log"
CustomLog "/private/var/log/apache2/{hostname}-access.log" combined
GET requests can then be found in /private/var/log/apache2/{hostname}-access.log
An easy and quick way to do this for debugging purposes is to write a function that logs the POST data.
function logPost() {
if (isset($_POST && !empty($_POST) {
foreach($_POST as $key => $value) {
error_log('=== _POST REQUEST ===');
error_log('_POST: '.$key.' => '.$value);
}
// OR serialise the data but this is less readable
error_log('=== _POST REQUEST ===');
error_log(serialise($_POST));
}
}
POST requests can then be found in /private/var/log/apache2/{hostname}-error.log
The GET request are logged in the access log file. Read the documentation you provided, especially the Access Log
part is important.
Your Apache host should be configured with something like:
LogLevel info
ErrorLog "/private/var/log/apache2/{hostname}-error.log"
CustomLog "/private/var/log/apache2/{hostname}-access.log" combined
GET requests can then be found in /private/var/log/apache2/{hostname}-access.log
An easy and quick way to do this for debugging purposes is to write a function that logs the POST data.
function logPost() {
if (isset($_POST && !empty($_POST) {
foreach($_POST as $key => $value) {
error_log('=== _POST REQUEST ===');
error_log('_POST: '.$key.' => '.$value);
}
// OR serialise the data but this is less readable
error_log('=== _POST REQUEST ===');
error_log(serialise($_POST));
}
}
POST requests can then be found in /private/var/log/apache2/{hostname}-error.log
answered Jan 2 at 14:41


G4HuG4Hu
179115
179115
Just to be clear, do you replace {hostname} with the hostname or is it a variable that is automatically replaced.
– James
Jan 3 at 11:04
Yes manually replace it with your hostname or use an ENV variable with the name if you have one
– G4Hu
Jan 3 at 11:07
Just to be clear and I may have to rewrite the question - I am looking to log GET requests made to another server NOT GET requests on this server. Will this still work?
– James
Jan 3 at 11:09
Ah, that would have been good to make more clear in the question. Apache can only log requests made TO it, not from it. At least as far a i know
– G4Hu
Jan 3 at 11:20
If you where to query your own serverhttp://host.example/index.php?query=test_api
this would be logged by Apache. If you make a request from inside phpheader(...)
for example, that will not be logged
– G4Hu
Jan 3 at 11:24
add a comment |
Just to be clear, do you replace {hostname} with the hostname or is it a variable that is automatically replaced.
– James
Jan 3 at 11:04
Yes manually replace it with your hostname or use an ENV variable with the name if you have one
– G4Hu
Jan 3 at 11:07
Just to be clear and I may have to rewrite the question - I am looking to log GET requests made to another server NOT GET requests on this server. Will this still work?
– James
Jan 3 at 11:09
Ah, that would have been good to make more clear in the question. Apache can only log requests made TO it, not from it. At least as far a i know
– G4Hu
Jan 3 at 11:20
If you where to query your own serverhttp://host.example/index.php?query=test_api
this would be logged by Apache. If you make a request from inside phpheader(...)
for example, that will not be logged
– G4Hu
Jan 3 at 11:24
Just to be clear, do you replace {hostname} with the hostname or is it a variable that is automatically replaced.
– James
Jan 3 at 11:04
Just to be clear, do you replace {hostname} with the hostname or is it a variable that is automatically replaced.
– James
Jan 3 at 11:04
Yes manually replace it with your hostname or use an ENV variable with the name if you have one
– G4Hu
Jan 3 at 11:07
Yes manually replace it with your hostname or use an ENV variable with the name if you have one
– G4Hu
Jan 3 at 11:07
Just to be clear and I may have to rewrite the question - I am looking to log GET requests made to another server NOT GET requests on this server. Will this still work?
– James
Jan 3 at 11:09
Just to be clear and I may have to rewrite the question - I am looking to log GET requests made to another server NOT GET requests on this server. Will this still work?
– James
Jan 3 at 11:09
Ah, that would have been good to make more clear in the question. Apache can only log requests made TO it, not from it. At least as far a i know
– G4Hu
Jan 3 at 11:20
Ah, that would have been good to make more clear in the question. Apache can only log requests made TO it, not from it. At least as far a i know
– G4Hu
Jan 3 at 11:20
If you where to query your own server
http://host.example/index.php?query=test_api
this would be logged by Apache. If you make a request from inside php header(...)
for example, that will not be logged– G4Hu
Jan 3 at 11:24
If you where to query your own server
http://host.example/index.php?query=test_api
this would be logged by Apache. If you make a request from inside php header(...)
for example, that will not be logged– G4Hu
Jan 3 at 11:24
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54008051%2flog-get-requests-and-querystring-in-php-apache%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
From the Apache Documentation -> Access log: "The server access log records all requests processed by the server." It explicitly contains an example where a GET request is logged (paragraph 8) Maybe you could compare the settings explained there with yours to see if your server logs incoming requests
– akraf
Jan 2 at 14:29