ssuresh07 Posted November 10, 2008 Share Posted November 10, 2008 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> Quote Link to comment Share on other sites More sharing options...
bhavik_thegame Posted November 17, 2008 Share Posted November 17, 2008 1. if($rs[1] == $txtUserName && $rs[2] == $txtPassword) { $_SESSION['uname']=$txtUserName; header('Location: index1.html'); } ================ Then on the login page write the following code on the top 2. if($_SESSION['uname']) { header('location:index1.html') } =================== Modify the code posted by you by point 1. We have just taken a session variable & stored the user name in that. Write the code point no. 2 on the above of the login page. This will check if a user is logged in or not. i.e username session variable is set or not. If it is set it wil not show login & redirect it to the index1.html ---- Dont foget to start the session on each page i.e "session_start()" Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.