Changing code to a class

Hi. Will cut a lot of the code out to make things simpler. Basically, I had this code

<?php
include("DB.php");

function displayStatus(){
   global $logged_in;
   include("LS.php");
   if($logged_in){
      loginDisplay();
   }
   else{
?>

<h1>Login</h1>
<form action="" method="post" onsubmit="return validate(this)">
<table align="center" border="0" cellspacing="0" cellpadding="3">
<tr><td>Username:</td><td><input type="text" name="username" maxlength="30"></td></tr>
<tr><td>Password:</td><td><input type="password" name="password" maxlength="30"></td></tr>
<tr><td colspan="2" align="left"><input type="checkbox" name="remember">
<font size="2">Remember me next time</td></tr>
<tr><td colspan="2" align="right"><input type="submit" name="submit" value="Login"></td></tr>
<tr><td colspan="2" align="left"><a href="Register.php">Register</a></td></tr>
</table>
</form>

<?php
   }
}

if(isset($_POST['submit'])){
   $md5pass = md5($_POST['password']);
   $result = checkUser($_POST['username'], $md5pass);

   $_POST['username'] = stripslashes($_POST['username']);
   $_SESSION['username'] = $_POST['username'];
   $_SESSION['password'] = $md5pass;
   
   }

   echo "<meta http-equiv=\\"Refresh\\" content=\\"0;url=$HTTP_SERVER_VARS[PHP_SELF]\\">";
   return;
}

$logged_in = checkStatus();
?>

The important thing is displayStatus function as this is what is called by the other class. Also, the variable at the bottom logged_in is very important, because its used across pages.

Now I tried recreating this as a class. I done.

<?php
include("DB.php");

class Form {
	
function Form(){
}

function displayStatus(){
   $logged_in = $this->checkStatus();
   include("LS.php");
   if($logged_in){
       loginDisplay();
   }else{
	   $this->showForm();
	   $this->processForm();
   }
}

function showForm(){
	echo "<h1>login Form</h1>";
	echo '<form action="" method="post" onsubmit="return validate(this)">';
	echo '  <table align="center" border="0" cellspacing="0" cellpadding="3">';
	echo '<tr><td>Username:</td>'
		.'<td><input type="text" name="username" maxlength="30"></td></tr>';
	echo '<tr><td>Password:</td>'
		.'<td><input type="password" name="password" maxlength="30"></td></tr>';
	echo '<tr><td colspan="2" align="left"><input type="checkbox" name="remember">'
		.'<font size="2">Remember me next time</td></tr>';
	echo '<tr><td colspan="2" align="right"><input type="submit" name="submit" value="Login"></td></tr>';
	echo '<tr><td colspan="2" align="left"><a href="Register.php">Register</a></td></tr>';
	echo '</table>';
	echo '</form>';   
}

function processForm(){
  if(isset($_POST['submit'])){
	 $md5pass = md5($_POST['password']);
	 $result = $this->checkUser($_POST['username'], $md5pass);
  
	 $_POST['username'] = stripslashes($_POST['username']);
	 $_SESSION['username'] = $_POST['username'];
	 $_SESSION['password'] = $md5pass;
	 
	 echo "<meta http-equiv=\\"Refresh\\" content=\\"0;url=$HTTP_SERVER_VARS[PHP_SELF]\\">";
	 return;
  }
}
}

}

?>

I call this up from another class like

<?php
    $uLog= new Form();
    $uLog->displayStatus();
?>

I dont know If I am recreating the displayStatus function correctly. I am also unsure If I placed the variable in a good location, as the class would not allow me to place it in the middle of knowhere. Everything from what I can tell works fine in terms of loggin the user in, but the variable logged_in does not seem to get into the other class, as when I log out in the other class, I get an error I throw myself.

Just really want to know what I can do to make it the same as the first code I posted.

Cheers

Why do you need this in a “class” for?
As far as I can tell, you are just using it for the sack of using it.

Yep, looks like class for class sake. Its not making anything more simple in the least. If anything more complex and convoluted. Proper PHP OO architecture really comes down to using the given patterns of PHP MVC that propagate the entire application. Without usng those generally code that is OO is just convoluted in nature. In this case the form processing logic could be moved to a controller and form a view/template combination. Depending on whether templates alone will make up the view layer or combination of a view class and template. Than the session information could be moved into a model, and called via the controller based on the specific, domain based business transaction.

Its problably because I come from a java background that I want to use classes. In php, I just think that when you echo something, it is simple to echo it onto the current page, rather that it being echoed onto a new page.