New to PHP : Need Help to create a login page using classes
Posted: Tue Nov 11, 2008 12:19 am
Hi,
I'm new to PHP, I have just started to develop an application.
I want to use Classes to built a login page.
I'm here posting my coding which is incomplete.
Someone give idea of completing it with handling sessions and how to redirect to another page.
and when pressing back button it should not goto login page again.
<?
class Login
{
public function __construct($username, $password)
{
require_once("Connection/db.php");
session_start();
$this->username = $username;
$this->password = $password;
$this->Validate();
}
public function __destruct()
{
}
protected function Validate()
{
$Query = "SELECT * FROM master_login WHERE username = ". $txtUserName ."";
$Execute = mysql_query($Query) or die('Query failed1: ' . mysql_error());
$rs =mysql_fetch_row($Execute);
if($rs[1] == $txtUserName && $rs[2] == $txtPassword)
header('Location: index1.html');
}
}
$objLogin = new Login("Guest","guest");
?>
<html>
<head>
<title>Test</title>
</head>
<body>
<form name = "frmlogin" method = "post" action="index1.html">
<table align="center">
<tr>
<th><a href="index1.html">Login</a></th>
</tr>
<tr>
<td><input type = "text" name = "txtUserName" /></td>
</tr>
<tr>
<td><input type = "text" name = "txtPassword" /></td>
</tr>
<tr>
<td>
<input type = "submit" name = "submit" value = "Submit" />
<input type = "reset" name = "reset" value = "Reset" />
</td>
</tr>
</body>
</html>
I'm new to PHP, I have just started to develop an application.
I want to use Classes to built a login page.
I'm here posting my coding which is incomplete.
Someone give idea of completing it with handling sessions and how to redirect to another page.
and when pressing back button it should not goto login page again.
<?
class Login
{
public function __construct($username, $password)
{
require_once("Connection/db.php");
session_start();
$this->username = $username;
$this->password = $password;
$this->Validate();
}
public function __destruct()
{
}
protected function Validate()
{
$Query = "SELECT * FROM master_login WHERE username = ". $txtUserName ."";
$Execute = mysql_query($Query) or die('Query failed1: ' . mysql_error());
$rs =mysql_fetch_row($Execute);
if($rs[1] == $txtUserName && $rs[2] == $txtPassword)
header('Location: index1.html');
}
}
$objLogin = new Login("Guest","guest");
?>
<html>
<head>
<title>Test</title>
</head>
<body>
<form name = "frmlogin" method = "post" action="index1.html">
<table align="center">
<tr>
<th><a href="index1.html">Login</a></th>
</tr>
<tr>
<td><input type = "text" name = "txtUserName" /></td>
</tr>
<tr>
<td><input type = "text" name = "txtPassword" /></td>
</tr>
<tr>
<td>
<input type = "submit" name = "submit" value = "Submit" />
<input type = "reset" name = "reset" value = "Reset" />
</td>
</tr>
</body>
</html>