josephbupe Posted March 13, 2013 Share Posted March 13, 2013 Hi, Can some one point me to any existing login script that I can learn from? joseph Quote Link to comment Share on other sites More sharing options...
rgopal101 Posted March 17, 2013 Share Posted March 17, 2013 <?phpsession_start();ob_start(); include"config.php";if(isSet($_SESSION['uid'])) { header('location:index.php'); } ?> <form method="post"> <table style="border:1px solid; margin-left:325px;" cellpadding="5" cellspacing="5"> <tr> <td colspan="3" align="center"><font color="#FF0000"> <?php if(isset($_POST['login'])) { $email=mysql_real_escape_string($_POST['email']); $pass=mysql_real_escape_string($_POST['password']); $pass=md5($pass); $q="select * from user where email='$email' and password='$pass'"; $a=mysql_query($q);$no=mysql_num_rows($a); if($no==1) { while($row=mysql_fetch_array($a)) { $verify=$row['active']; $id=$row['id']; } if($verify==1) { $_SESSION['uid']=$id; header('location:index.php'); } else { echo "Your Account is Not Activated !!";} }else { echo "Incorrect Username or Passwword"; } } ?></font></td> </tr> <tr> <td>Email</td><td> :</td><td><input type="text" name="email" Required/></td> </tr> <tr> <td>Password</td><td> :</td><td><input type="text" name="password" Required/></td> </tr> <tr> <td colspan="3" align="center"><input type="submit" name="login" value="Login"></td> </tr> </table></form> Quote Link to comment Share on other sites More sharing options...
PaulRyan Posted March 19, 2013 Share Posted March 19, 2013 Rgopal101, the code you have provided has many flaws. - Logic code should be placed at the top of the file, not below the login form. - Use of MySQL is discouraged, use MySQLi or PDO. - Never use MD5 for passwords, use something like the crypt function or PHPass(my preference) Google both. - You don't use the exit function after a header redirect, this allows the rest of the on page code to processed and ran. There are other things too, but those are preferences. Quote Link to comment Share on other sites More sharing options...
DaveyK Posted March 19, 2013 Share Posted March 19, 2013 In addition, since you've requested a script for learning purposes, I would suggest an extended tutorial. This is a video series by alex garett from phpacademy. Its very large, you can cut to the episodes you want if you like. Dont take all he says for granted, even he makes mistakes, but the logic behind it is great for leaning. Its much better fro learning then copy pasting. 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.