Every time I run this code, only "Not from a" gets written, whether the location is “a” or not.
function logsIn($dir, $account, $balance) {
$d = date("D F d Y - h:i A");
$file = fopen("logs/$dir.txt", "a");
if ($_SESSION['pass'] == "123") {
if ($api["Location"] != "a")
fwrite($file, "<span style='color:#FF0000;text-align:center';>Not from a.</span>");
else
fwrite($file, "From a.");
}
You are using a variable called
$apiin your function, but that variable is not defined anywhere.So,
$api["Location"]cannot have the value'a'— which is why the you always get"Not from a".Note : If you have a
$apivariable that’s defined outside of your function, then, it is not visible from inside that function.For more information about this, you should take a look at the Variable scope section of the manual.
As a solution, I suppose you could modify your code so :
$apiis expected as a parameter by yourlogsIn()function,You could also make the
$apivariable (if it exists outside of your function) visible from inside the function, using theglobalkeyword — but it’s not good practice, as it makes your function dependant on an external variable.