Hy,
I'm, quite new to moodle, and it's functions. I need to write the Userid of the person calling my script to get written in a .txt file. My script works so far, but only sometimes. Sometimes $USER is just an empty array with one variable called id which is 0, and sometimes it works perfectly.
$configphp is the path to the config.php and require is working... it returns 1.
Here is my script:
require($configphp);
global $USER;
//require works this way
//Userid:
$info = $USER->id; //and thats the point --> sometimes just returns 0 with every logged in user, somtimes works like a charm
//filehandle
$dokument = "./Personen.txt";
$filehandle = fopen ($dokument, "a");
//Zeilenumbruch erleichtert späteres einlesen in Array
$text = "$info\n";
//Schreiben
fwrite ($filehandle,$text);
//filehandle schließen
fclose ($filehandle);
Hope you can help me. Do i have to require something else too?
Greetings and Thanx,
Didi