Accessing a Global Variable from Within a Function
<?php
$GLOBALS['user'] = "myusername";
$GLOBALS['pass'] = "mypassword";
function validatelogin ($username, $password){
if (strcmp ($username, $GLOBALS['user']) == 0 && strcmp ($password, $GLOBALS['pass']) == 0){
return true;
} else {
return false;
}
}
if (validatelogin ("myusername","mypassword")){
echo "You are logged in correctly";
} else {
echo "You have an incorrect username and/or password";
}
?>
Related examples in the same category