Skip to content

Instantly share code, notes, and snippets.

@Robert-IMT
Last active February 10, 2021 06:39
Show Gist options
  • Select an option

  • Save Robert-IMT/98d5e9f6aa86b8f922cf6196b80320a9 to your computer and use it in GitHub Desktop.

Select an option

Save Robert-IMT/98d5e9f6aa86b8f922cf6196b80320a9 to your computer and use it in GitHub Desktop.
/**
* Write variable value to file
*
* @param mixed $data
* @param string $file
*/
function writeToLogFile( $data, $file = 'tmp/log.txt' ) {
$developers = array(
'127.0.0.1', // localhost
'100.100.100.100', // Work
);
if ( in_array( $_SERVER['REMOTE_ADDR'], $developers ) ) {
if ( is_object( $data ) ) {
$data = (array)$data;
}
if ( ! is_array( $data ) ) {
$data = array( '$data' => $data );
}
$current = PHP_EOL . '--->>> ' . date( 'd.m.Y H:i:s' ) . PHP_EOL;
$current .= var_export( $data, true );
$current .= PHP_EOL . '<<<---' . PHP_EOL;
file_put_contents( $file, $current, FILE_APPEND | LOCK_EX );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment