For starters, you should format the code properly, e.g.,
<?php
$datetoday = date('j, F, Y');
function ifname($name = 'Willian') {
if ($name == 'Willian') {
echo 'Welcome Mr. $name, today is, ' . $datetoday . '. \n ' . '<br>';
} else {
echo 'You are not Willian.\n ' . '<br>' . 'Logged out';
}
}
?>
So, $datetoday is not in the scope of the ifname function, hence you cannot access it from within the ifname function. One simple solution is to move the call of date, e.g.,
<?php
function ifname($name = 'Willian') {
if ($name == 'Willian') {
echo 'Welcome Mr. $name, today is, ' . date('j, F, Y') . '. \n ' . '<br>';
} else {
echo 'You are not Willian.\n ' . '<br>' . 'Logged out';
}
}
You could also declare $datetoday global in ifname, but that is a poor solution in this case.