I am taking a class on PHP, and we are learning about object classes. I have been told to create an object class called 'LoginBox' that will validate users and redirect them to a new page depending on whether their information was correct or not. We have yet to study MYSQL, so I am unable to use that for this example. I have been told that I am able to use a static username and password for this specific problem, since we have yet to study databases.
My problem is that I don't know how to carry info from one page to another using an Object class. I feel like if I can get that figured out, my class will do just about everything I need it to do, but its hard to tell for sure since this part is preventing me from seeing the results. As you can see in my code, I try to use $_Post, but now matter what I try the information does not carry over to the new page, and it displays nothing. Does anyone have any suggestions on how to tackle this problem? Thanks in advance!
class LoginBox {
public $userName = "user123";
public $password = "pass123";
public $var1;
public $var2;
public function makeTable() {
echo '<form action="loggedin.php" method="post">
Name: <input type="text" name="username"><br>
E-mail: <input type="text" name="password"><br>
<input type="submit">
</form>';
}
public function __construct() {
$this->var1=isset($_POST['username']) ? $_POST['username'] : null;
$this->var2=isset($_POST['password']) ? $_POST['password'] : null;
}
public $SuccessRedirect = "Welcome back!";
public $FailRedirect = "You have entered the incorrect information. Please return and try again.";
public function action() {
if ($this->$var1 <> $this->$userName || $this->$var2 <>$this->$password) {
echo $failRedirect;
}
else {
echo $SuccessRedirect;
}
}
}