Last active
February 10, 2021 06:39
-
-
Save Robert-IMT/98d5e9f6aa86b8f922cf6196b80320a9 to your computer and use it in GitHub Desktop.
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
| /** | |
| * 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