dongzaobei0942 2016-05-12 12:18
浏览 28

file_put_contents不在一个地方工作,但在代码中的其他地方工作

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);
}
  • 写回答

2条回答 默认 最新

  • dpxua26604 2016-05-12 12:22
    关注

    You can extend the file with a hierarchy or you only have to include this file with the include statement.

    Hierarchy

    <?php
    
        class ClassA extends ClassB {
    
    
        }
    

    Include

    log.php
    <?php
    
    $logA = 'mylogA';
    $logB = 'otherlog';
    
    ?>
    
    test.php
    <?php
    
    
    include 'log.php';
    
    echo "Show my $logA"; 
    
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行