I am trying out classes, and have made just a small one and wondered is this the best way to code this problem using classes??
<?php
class classname
{
var $username;
var $stored_username;
// Function to check if details are correct.
function check_var($username)
{
if ($this->username != $this->stored_username)
{
return "Login Bad";
}
else
{
return "Login GOOD";
}
}
// Function to get a variable.
function get_var($var_name)
{
return $this->$var_name;
}
// Function to set a variable.
function set_var($var_name, $new_value)
{
$this->$var_name = $new_value;
}
}
$test = new classname();
$test->set_var("stored_username","admin");
echo $test->check_var($test->set_var("username","test"));
// Debugging info.
echo "<br>";
echo "Stored - ".$test->get_var("stored_username");
echo "<br>";
echo "Entered - ".$test->get_var("username");
?>
I was trying to make a very simple login, that checks a value to see if it is the same as the one entered, if it is then a Login GOOD message comes up but if it is inncorrect the Login BAD comes up.
What do you think. How could i imporve it?