0

so i decided to brush back up on my skills in html and i wanted to create website that has a login page for members and administrators or for new members to sign up i see php is the new thing. I have created the actual homepage and the links to different pages within the websites those that i want just for members/admin. only and those everyonecan seeif you can help em i would be much abliged thanks. by the way i am doing everythign from scratch using notepad

5
Contributors
5
Replies
19
Views
6 Years
Discussion Span
Last Post by baig123
0

lol @magic media thanks..
but i truly do nto want to do it in php but if i have to then thats okay like i said I have one main website with different websites integrated in it... and i need a login and registration for the members only parts of those different webpages and I already did the websites i just need the logins for each individual one thanks

0

Couple of thoughts - you can do logins with different technologies - I have only really used php and mysql to do it. I fyou want registration as well, then its quite a few pages. I taught myself using a book (which was FAB and I can give you the name if you want).

Easier option might be to consider using something like joomla - all the php stuff is done already, and it handles logins and so forth. The downside of this is that if you haven't used joomla before it can be quite a steep learning curve to get to grips with if you want to make your own look and feel rather than use the provided template.

Lots to think about - depends how much time you have I reckon!

0

Follow this tutorial, I will use mysql as there are still so many wanna be programmers who are using it. But we will sanitize it so it will still look secured.

Let us prepare our database table.

Database name: login
Database table: member

Using phpMyAdmin, create a database called "login".

Now select the database that you have created. Click on the SQL tab and paste the following sql code.

CREATE TABLE `login`.`member` (
  `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, 
  `username` VARCHAR(30) NOT NULL, 
  `password` CHAR(128) NOT NULL, 
  `email` VARCHAR(50) NOT NULL, 
  `salt` CHAR(128) NOT NULL
) ENGINE = InnoDB;

Create a Registration Form called "registration.html". For the meantime let's use table for our design.

<!<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Register</title>
</head>
<body>
<form name="register" action="register.php" method="post">
    <table width="510" border="0">
        <tr>
            <td colspan="2"><p><strong>Registration Form</strong></p></td>
        </tr>
        <tr>
            <td>Username:</td>
            <td><input type="text" name="username" maxlength="20" /></td>
        </tr>
        <tr>
            <td>Password:</td>
            <td><input type="password" name="password1" /></td>
        </tr>
        <tr>
            <td>Confirm Password:</td>
            <td><input type="password" name="password2" /></td>
        </tr>
        <tr>
            <td>Email:</td>
            <td><input type="text" name="email" id="email" /></td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td><input type="submit" value="Register" /></td>
        </tr>
    </table>
</form>
</body>
</html>

Now create registration script called "register.php".

First, let us receive the data from our registration form.

<?php
//retrieve our data from POST
$username = $_POST['username'];
$password1 = $_POST['password1'];
$password2 = $_POST['password2'];
$email = $_POST['email'];
if($password1 != $password2)
    header('Location: registration.html');
if(strlen($username) > 30)
    header('Location: registration.html');
    $hash = hash('sha256', $password1);
function createSalt()
{
    $text = md5(uniqid(rand(), true));
    return substr($text, 0, 3);
}
$salt = createSalt();
$password = hash('sha256', $salt . $hash);
$conn = mysql_connect('localhost', 'root', '');
mysql_select_db('login', $conn);
//sanitize username
$username = mysql_real_escape_string($username);
$query = "INSERT INTO member ( username, password, email, salt )
        VALUES ( '$username', '$password', '$email', '$salt' );";
mysql_query($query);
mysql_close();
header('Location: login.php');
?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.