I have a PHP script that calls the function fileRead2 function from the file fileRead2.php.
The function below reads username.txt (Which display's the username).
vim fileRead2.php
<?php
function fileRead2() {
global $fh, $line;
$fh = fopen('username.txt','r');
while ($line = fgets($fh)) {
// <... Do your work with the line ...>
echo($line);
}
fclose($fh);
}
?>
If I run the linux command cat on the linux filesystem it show's 'tjones' (the username.)
I run the below in a script.
<?php
// Read the Username
require_once('fileread2.php');
$userName = fileRead2();
echo $userName;
var_dump($userName);
>?
It echo's $userName
that display's 'tjones' however var_dump show's its output as NULL.
Is there any reason why var_dump shows the $userName
variable as NULL, when it should be string 'tjones'?
The reason I ask is because I need the variable $userName;
for other parts of code and because it's NULL nothing else is working, and I have no idea why?