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