Created
October 23, 2023 00:55
-
-
Save kingkool68/e4f217e4fbe7c6463cd6d67de73104f5 to your computer and use it in GitHub Desktop.
Log $_GET or $_POST data to a CSV file. Example: index.php?bar=bar&foo=foo&baz=baz&bad-data=dont-save would append the following to the data.csv file: 1698022463,foo,bar,baz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Merge the expected data with the data recieved | |
$expected_data = array( | |
'timestamp' => '', | |
'foo' => '', | |
'bar' => '', | |
'baz' => '', | |
); | |
$data = array_merge( $expected_data, $_REQUEST ); | |
// Filter out any extra keys that might be passed in | |
$data = array_intersect_key( $data, $expected_data ); | |
// If the data is empty then bail | |
if ( empty( $data ) ) { | |
return; | |
} | |
// Set the timestamp value to the current time | |
$data['timestamp'] = time(); | |
// Append the data to a CSV file | |
$handle = fopen( 'data.csv', 'a' ); | |
fputcsv( $handle, $data ); | |
fclose( $handle ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment