Jump to content

Login script help


addinol

Recommended Posts

Hey, could someone help me with login script ? I've got registration script.

 

It contains 3 files:

 

reg.php

<?php

require_once 'database.php';
?>

<h1><strong>Register</strong></h1>

<form name="register" method="post" action="regcheck.php">

  <label>
  <input type="text" name="user" id="user"> Username<br />
  </label>
  
  <br />
  
  <label>
  <input type="password" name="pass" id="pass"> Password<br />
  </label>
  
  <br />
  
  <label>
  <input type="text" name="email" id="email"> Email<br />
  </label>
  
  <label>
  <input type="submit" name="reg" id="reg" value="Register">
  </label>
  
</form>

 

regcheck.php

<?php
$email = $_POST['email'];

if(
    isset( $_POST['user'] ) &&
    isset( $_POST['pass'] ) &&
    isset( $_POST['email'] )
)
{
    if( strlen( $_POST['user'] ) < 4 )
    {
        echo "Username is too short";
    }
    elseif( strlen( $_POST['pass'] ) < 4 )
    {
        echo "Password is too short";
    }
    elseif(!filter_var($email, FILTER_VALIDATE_EMAIL))
{
    echo "Bad email address";
}  
    elseif( $_POST['pass'] == $_POST['user'] )
    {
        echo"Username and password can't be the same";
    }
    else
    {
        include( 'database.php' );

        $username = mysql_real_escape_string( $_POST['user'] );
        $password = mysql_real_escape_string( $_POST['pass'] );
        $email = mysql_real_escape_string( $_POST['email'] );

        $sqlCheckForDuplicateN = "SELECT username FROM user WHERE username = '". $username ."'";
	$sqlCheckForDuplicateE = "SELECT email FROM user WHERE email = '". $email ."'";
        
        if( mysql_num_rows( mysql_query( $sqlCheckForDuplicateE ) ) == 0 && mysql_num_rows( mysql_query( $sqlCheckForDuplicateN ) ) == 0 )
        {
            $sqlRegUser =     "INSERT INTO
                        user( username, password, email )
                    VALUES(
                        '". $username ."',
                        '". $password ."',
                        '". $email ."'
                        )";

            if( !mysql_query( $sqlRegUser ) )
            {
                echo "You Could Not Register Because Of An Unexpected Error.";
            }
            else
            {
                echo "You Are Registered And Can Now Login";
            }
        }
        elseif( !(mysql_num_rows( mysql_query( $sqlCheckForDuplicateE ) ) == 0))
        {
            echo "The Email You Have Entered Is Already Being Used. Please Try Another One.";
        }
        elseif( !(mysql_num_rows( mysql_query( $sqlCheckForDuplicateN ) ) == 0))
        {
            echo "The Username You Have Entered Is Already Being Used. Please Try Another One.";
        }
        elseif( !(mysql_num_rows( mysql_query( $sqlCheckForDuplicateE ) ) == 0) && !(mysql_num_rows( mysql_query( $sqlCheckForDuplicateN ) ) == 0))
        {
            echo "The Email and Username You Have Entered Is Already Being Used. Please Try Another One.";
        }
        
        
    }
}
else
{
    echo "You Could Not Be Registered Because Of Missing Data.";
}
?>

 

database.php

<?
$con = mysql_connect('host','username','password');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db('dbname');
?>

 

 

So could someone help me with login ???

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/219351-login-script-help/
Share on other sites

I would use a different script that uses Sessions, they are much easier to work with and more secure. I have a great script that I use that was really easy to implement and modify to my needs. I can't remember exactly where I got it but found it searching on Google. Hope this helps.

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

This is more of a forum for learning how to do PHP, and not really for people just doing it for you.

 

If you really want to learn, start writing some code and ask for help along the way.

 

If you want someone to just do it for you, try the Freelance area.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.