Jump to content

Recommended Posts

<?php
session_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>
                       

Link to comment
https://forums.phpfreaks.com/topic/275613-login-script/#findComment-1419140
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/275613-login-script/#findComment-1419497
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/275613-login-script/#findComment-1419500
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.