Login/register

Status
Not open for further replies.

Dobby

Member
Nov 8, 2010
156
5
Hello. Im trying to make a login and register system. It needs to have on the register: Email, Password, Username, Name

And once logged in directed to a page where all the stuff is. On this page i want to have a chat room that uses your username/name

I have looked everywhere for something like this but i have had no luck. Could someone help ?
 

GarettM

Posting Freak
Aug 5, 2010
833
136
First You Need to create a table for Email, Password, Username, Name
Then You need To Learn Javascript or Jquery Samething Kinda
Then Use PHP to login and register here is to help you get started!! :)
PHP:
<?php
###########################################################
# Simple Login And Register - Created By GarettMcCarty    #
###########################################################
 
class accounts {
    public function login()
    {
        $username = mysql_real_escape_string($_POST['username']);
        $password = md5($_POST['password']);
       
        if(filter_var($username, FILTER_VALIDATE_EMAIL))
        {
            $query  = mysql_query("SELECT * FROM tablename WHERE email='".$username."' LIMIT 1");
            $result = mysql_fetch_array($query);
            if(mysql_num_rows($query) > 0)
            {
                if($result['password'] == $password)
                {
                    header("Location: pagetoredirect.php");
                    $_SESSION['username'] = $result['username'];
                }
            }
        } else {
          $query  = mysql_query("SELECT * FROM tablename WHERE username='".$username."' LIMIT 1");
          $result = mysql_fetch_array($query);
          if(mysql_num_rows($query) > 0) 
          {
              if($result['password'] == $password)
              {
                    header("Location: pagetoredirect.php");
                    $_SESSION['username'] = $result['username'];
              }
          }
        }
    }
    public function register()
    {
        // write register here
    }
}
 
?>
 
Jan 17, 2012
649
166
Here's the register:
PHP:
<?php
 
$username = strip_tags($_POST['username']);
$email = strip_tags($_POST['email']);
$password = strip_tags($_POST['password']);
$repeatpassword = strip_tags($_POST['repeatpassword']);
 
 
if (isset($_POST['submit'])) {
 
 
    if ($username && $email && $password && $repeatpassword) {
        if ($password == $repeatpassword) {
            if (strlen($username) > 30) {
                echo "Your username can't be longer than 30 characters.";
            } else {
                if (strlen($email) < 6) {
                    echo "This email is invalid.";
                } else {
                    if (strlen($password) > 35 || strlen($password) < 6) {
                        echo "Your password must be between 6 and 35 characters.";
                    } else {
                        $ch = mysql_query("SELECT username FROM users WHERE username='$username'");
                        $check = mysql_num_rows($ch);
 
                        if ($check != 0) {
                            echo "The username $username already exists.";
                        } else {
 
                            $hashpassword = md5($password);
                            $insert = "INSERT INTO users (username,email,password) VALUES ('$username','$email','$hashpassword')";
                            mysql_query($insert);
                            $_SESSION['user']=$username;
                            $_SESSION['user_id']=$id;
                            header("location: me.php");
                        }
                    }
                }
            }
        }
        else
            echo "Password does not match";
    }
    else
        echo "Please fill in all the fields";
 
    }
 
 
?>
Taken from 's membership system.
 

GarettM

Posting Freak
Aug 5, 2010
833
136
What about xss protection should u add htmlspecialchars? or does strip_tags do that already ?

PHP:
 htmlspecialchars()
mysql_real_escape_string()
 
Status
Not open for further replies.

Users who are viewing this thread

Top