Im new to PHP, but used to Java. I have a file, dd-functions.php that contains a function (writeToLog). This function will create a variable with the log-statement, then write it to a file.
The strange thing is that this works perfectly when it is called from one php-file (file1.php), but when called from another php-file (file2.php), it does not write anything to the file. In both file1.php and file2.php, the functions.php is included once.
How is this even possible?
Function.php
/* Log for user */
function writeToLog($user, $analyseName, $remaining_downloads) {
$uid = $user->ID;
$userdata = get_userdata($uid);
if ($userdata->first_name) {
$username = $userdata->first_name . ' ' . $userdata->last_name;
} else {
$username = $userdata->user_login;
}
date_default_timezone_set('Europe/Oslo');
$date = date('d.m.Y H:i:s');
$s2member_access_level = get_user_field ("s2member_access_level", $uid);
$userLog = $uid . "\t" . $date . "\t" . $username . "\t" . $user->user_email . "\t" . $analyseName . "\t" . $remaining_downloads . "\t" . $s2member_access_level . "
";
file_put_contents('analyse-email-click-log.txt', $userLog , FILE_APPEND);
}