Jump to content

Does anyone know how to make users and accounts on a website?


Cyber1AS

Recommended Posts

wow... um... vague...

basically... you want a table in your database for users with a spot for a id/username/password/etc.

then you have on your page a spot to login, which then pulls up the account, and saves the account in a session...
Link to comment
Share on other sites

Just do:

CREATE TABLE `users` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`username` VARCHAR( 255 ) NOT NULL ,
`password` VARCHAR( 255 ) NOT NULL ,
`email` VARCHAR( 255 ) NOT NULL ,
`ip` VARCHAR( 255 ) NOT NULL ,
`confirm` INT NOT NULL DEFAULT '0' ,
`confirm2` INT ( 75 ) NOT NULL
) ENGINE = MYISAM ;

And then make a file called form.php //will store your form.

[code=php:0]
<?php
echo "<form name=register method=post action=register.php>\n
<table border=0 cellspacing=3 cellpadding=2>\n
<tr><td>
Username:</td>
<td><input type=text name=username></td>
</tr>
<tr><td>
Password:</td>
<td><input type=password name=pass1></td>
</tr>
<tr><td>
Confirm:</td>
<td><input type=password name=pass2></td>
</tr>
<tr><td>
Email:</td>
<td><input type=text name=email1></td>
</tr>
<tr><td>
Confirm:</td>
<td><input type=text name=email2></td>
</tr>
<tr><td colspan=2>
<input type=hidden name=act value=register>
<input type=submit value=Register>
</td></tr>
</table>
</form>";
?>
[/code]

Then we'll make register.php

[code=php:0]
<?php
  $act = $_POST['act'];

if(!isset($act)){ //you could do empty($act)
include_once('form.php');
die();
}

if($act == register){
$username = $_POST['username'];
$password = md5($_POST['pass1']);
$confpwrd = md5($_POST['pass2'];
$email = $_POST['email1'];
$confemal = $_POST['email2'];

if(isset($username) && isset($password) && isset($confpwrd) && isset($email) && isset($confemal)){
//will check for password equaling
if($password != $confpwrd){
echo "<b>Your passwords did not match!</b><br><br>";
include_once('form.php');
die();
}

//will check length of pw
if(str_len($_POST['pass1']) < 6){
echo "<b>Your password was too short!</b><br><br>";
include_once('form.php');
die();
}

//will check for email equaliing (wont go into correct email syntax if they want to register then they shall confirm it
if($email != $confemal){
echo "<b>Your email addresses did not match!</b><br><br>";
include_once('form.php');
die();
}

//checking if user name exists
$sql = "SELECT `username` FROM `users` WHERE `username` ='$username'";
$res = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($res) == 1){
echo "<b>The username $username is already in use!</b><br><br>";
include_once('form.php');
die();
}

//if does exist check length
if(str_len($username) < 4){
echo "<b>The username you entered was too short!</b><br><br>";
include_once('form.php');
die();
}

//will check if IP already exists
$sql = "SELECT `ip` FROM `users` WHERE `ip` ='$_SERVER[REMOTE_ADDR]'";
$res = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($res) == 1){
echo "<b>Your IP Address is already in use!</b><br><br>";
include_once('form.php');
die();
}

//if everything is good then we will insert into the database
$rand = mt_rand(10,30);
$sql = "INSERT INTO `users` (`username`,`password`,`email`,`ip`,`confirm`,`confirm2`) VALUES('$username','$password','$email','$_SERVER[REMOTE_ADDR]','0','$rand')";
$res = mysql_query($sql) or die(mysql_error());
if($res){
echo "<b>Thank you for registering!</b>";
//now will send email to the person with confirmation link
$message = "Confirmation for yoursitenamehere

http://yoursitename.com/confirm.php?num=$rand";
$headers .= 'From: yoursitename <jon@genius.com>\r\n';
$headers .= 'Reply-To: yoursitename <jon@genius.com>\r\n';
$headers .= 'Return-Path: yoursitename <jon@genius.com>\r\n';
$headers .= "X-Mailer: PHP v".phpversion(); 
$mail = mail($email,'WebsiteName Confirmation',$message,$headers);
}
}else {
echo "<b>You did not fill out all the information!</b><br><br>\n";
include_once('form.php');
die();
}
?>
[/code]

Then make a file called confirm.php

[code=php:0]
<?php
$num = $_GET['num'];

if(!isset($num)){ //could use empty($num)
echo "You did not specify a confirmation code!";
}else {
$sql = "SELECT * FROM `users` WHERE `confirm2` ='$num'";
$res = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($res);
if($row[confirm] == 1){
echo "<b>This account has already been confirmed!";
}else {
$sql = "UPDATE `users` SET `confirm` =1";
$res = mysql_query($sql) or die(mysql_error());
if($res){
echo "<b>Your account $row[username] has been confirmed!</b>";
}
}
}
?>
[/code]

I haven't tested it, I just made it, so yeah.
Link to comment
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.