User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the HTML and CSS section within the Web Development category of DaniWeb, a massive community of 402,860 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,971 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our HTML and CSS advertiser: Lunarpages Web Hosting
Views: 9909 | Replies: 25
Reply
Join Date: Nov 2007
Posts: 1
Reputation: vinomashwin is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
vinomashwin vinomashwin is offline Offline
Newbie Poster

Question To create a registration page and login page

  #1  
Nov 17th, 2007
I want to know how to create a registration page and login page ... any tutorials about this and i need some complete web templates too(not just home page)... can any one help me.....any ref plz
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2007
Posts: 2,537
Reputation: MidiMagic is on a distinguished road 
Rep Power: 7
Solved Threads: 111
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Posting Maven

Re: To create a registration page and login page

  #2  
Nov 19th, 2007
You need a server-side script.
Daylight-saving time uses more gasoline
Reply With Quote  
Join Date: Jun 2007
Posts: 178
Reputation: macneato is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 12
macneato's Avatar
macneato macneato is offline Offline
Junior Poster

Re: To create a registration page and login page

  #3  
Nov 22nd, 2007
Simple PHP login:

Create a database (mysqladmin)

Name the table "dbUsers." It will need 4 fields:

Name Type Addition
id int(10) Primary Key, AUTO_INCREMENT
username varchar(16) Unique
password char(16)
email varchar(25)


Create a new file and name it dbConfig.php This will file will connect to the database

<?
// Replace the variable values below
// with your specific database information.
$host = "localhost";
$user = "UserName";
$pass = "Password";
$db   = "dbName";

// This part sets up the connection to the 
// database (so you don't need to reopen the connection
// again on the same page).
$ms = mysql_pconnect($host, $user, $pass);
if ( !$ms )
{
echo "Error connecting to database.\n";
}

// Then you need to make sure the database you want
// is selected.
mysql_select_db($db);
?>

Registration name this file "register.php"

<?php

// dbConfig.php is a file that contains your
// database connection information. This
// tutorial assumes a connection is made from
// this existing file.
include ("dbConfig.php");


//Input vaildation and the dbase code
if ( $_GET["op"] == "reg" )
 {
 $bInputFlag = false;
 foreach ( $_POST as $field )
  {
  if ($field == "")
   {
   $bInputFlag = false;
   }
  else
   {
   $bInputFlag = true;
   }
  }
 // If we had problems with the input, exit with error
 if ($bInputFlag == false)
  {
  die( "Problem with your registration info. "
   ."Please go back and try again.");
  }

 // Fields are clear, add user to database
 //  Setup query
 $q = "INSERT INTO `dbUsers` (`username`,`password`,`email`) "
  ."VALUES ('".$_POST["username"]."', "
  ."PASSWORD('".$_POST["password"]."'), "
  ."'".$_POST["email"]."')";
 //  Run query
 $r = mysql_query($q);
 
 // Make sure query inserted user successfully
 if ( !mysql_insert_id() )
  {
  die("Error: User not added to database.");
  }
 else
  {
  // Redirect to thank you page.
  Header("Location: register.php?op=thanks");
  }
 } // end if


//The thank you page
elseif ( $_GET["op"] == "thanks" )
 {
 echo "<h2>Thanks for registering!</h2>";
 }
 
//The web form for input ability
else
 {
 echo "<form action=\"?op=reg\" method=\"POST\">\n";
 echo "Username: <input name=\"username\" MAXLENGTH=\"16\"><br />\n";
 echo "Password: <input type=\"password\" name=\"password\" MAXLENGTH=\"16\"><br />\n";
 echo "Email Address: <input name=\"email\" MAXLENGTH=\"25\"><br />\n";
 echo "<input type=\"submit\">\n";
 echo "</form>\n";
 }
// EOF
?>

Login name this file "login.php"
<?php
session_start();
// dBase file
include "dbConfig.php";

if ($_GET["op"] == "login")
 {
 if (!$_POST["username"] || !$_POST["password"])
  {
  die("You need to provide a username and password.");
  }
 
 // Create query
 $q = "SELECT * FROM `dbUsers` "
  ."WHERE `username`='".$_POST["username"]."' "
  ."AND `password`=PASSWORD('".$_POST["password"]."') "
  ."LIMIT 1";
 // Run query
 $r = mysql_query($q);

 if ( $obj = @mysql_fetch_object($r) )
  {
  // Login good, create session variables
  $_SESSION["valid_id"] = $obj->id;
  $_SESSION["valid_user"] = $_POST["username"];
  $_SESSION["valid_time"] = time();

  // Redirect to member page
  Header("Location: members.php");
  }
 else
  {
  // Login not successful
  die("Sorry, could not log you in. Wrong login information.");
  }
 }
else
 {
//If all went right the Web form appears and users can log in
 echo "<form action=\"?op=login\" method=\"POST\">";
 echo "Username: <input name=\"username\" size=\"15\"><br />";
 echo "Password: <input type=\"password\" name=\"password\" size=\"8\"><br />";
 echo "<input type=\"submit\" value=\"Login\">";
 echo "</form>";
 }
?>

Members Area name this file "members.php", and include on pages that are only for registered users
?php
session_start();

if (!$_SESSION["valid_user"])
{
// User not logged in, redirect to login page
Header("Location: login.php");
}

// Member only content
// ...
// ...
// ...

// Display Member information
echo "<p>User ID: " . $_SESSION["valid_id"];
echo "<p>Username: " . $_SESSION["valid_user"];
echo "<p>Logged in: " . date("m/d/Y", $_SESSION["valid_time"]);

// Display logout link
echo "<p><a href=\"logout.php\">Click here to logout!</a></p>";
?>

logout name this file "logout.php"
<?php
session_start();
session_unset();

session_destroy();
// Logged out, return home.
Header("Location: index.php");
?>

There you go... need more help or confused, just ask.

If this information solved your problem. Please add to my reputation.
Thanks
macneato
Last edited by macneato : Nov 22nd, 2007 at 7:10 am. Reason: typo
Reply With Quote  
Join Date: Nov 2007
Posts: 13
Reputation: ViroGen is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
ViroGen ViroGen is offline Offline
Newbie Poster

Re: To create a registration page and login page

  #4  
Nov 26th, 2007
THIS IS GREAT! Thank you! One thing... how can I get it so that people can request their password when and if they loose it?

Also.. it seems that I had to change the type for PASSWORD to TXT in order for it to work..
Reply With Quote  
Join Date: Nov 2007
Posts: 13
Reputation: ViroGen is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
ViroGen ViroGen is offline Offline
Newbie Poster

Re: To create a registration page and login page

  #5  
Jan 12th, 2008
How can I have it so that fields are required? Also, how can I have a password field that they type in twice to make sure they typed it in correctly? Two password fields that check each other.

Also, using this code, how can I get users to retrieve their password/login based on their email? I have really been trying to to figure this out with no luck. Please help1
Reply With Quote  
Join Date: Nov 2007
Posts: 13
Reputation: ViroGen is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
ViroGen ViroGen is offline Offline
Newbie Poster

Re: To create a registration page and login page

  #6  
Jan 12th, 2008
How can I have it so that fields are required? Also, how can I have a password field that they type in twice to make sure they typed it in correctly? Two password fields that check each other.

Also, using this code, how can I get users to retrieve their password/login based on their email? I have really been trying to to figure this out with no luck. Please help!
Reply With Quote  
Join Date: Nov 2007
Posts: 13
Reputation: ViroGen is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
ViroGen ViroGen is offline Offline
Newbie Poster

Question Re: To create a registration page and login page

  #7  
Jan 12th, 2008
One more question. How can I tell user the username or email is already registered rather than getting the cant add user to database page?
Reply With Quote  
Join Date: Jun 2007
Posts: 178
Reputation: macneato is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 12
macneato's Avatar
macneato macneato is offline Offline
Junior Poster

Re: To create a registration page and login page

  #8  
Nov 22nd, 2007
Oh, to test your php, you'll need a server. I sugguest working on localhost. Lots of ways to do this. Easyphp is the simplest to setup. Place all files in the installation directory/publicHTML.
Reply With Quote  
Join Date: Jun 2007
Posts: 178
Reputation: macneato is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 12
macneato's Avatar
macneato macneato is offline Offline
Junior Poster

Re: To create a registration page and login page

  #9  
Nov 26th, 2007
With the password field. Change the type to varchar(25)

As for requesting passwords.

Yes. It can be done.
Ask the user to enter their email address.
select password from your_db where email_address = 'their_address'
Use the mail() function to send the password to the email address.

SQL:
SELECT
dbusers.password
FROM
dbusers
WHERE
(dbusers.email = 'pforgot')

'pforgot' is any name you've given to the form text input. Will write up a full script as soon as i get time. It's monday morning.. Things are a little hectic.
Reply With Quote  
Join Date: Nov 2007
Posts: 13
Reputation: ViroGen is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
ViroGen ViroGen is offline Offline
Newbie Poster

Re: To create a registration page and login page

  #10  
Nov 26th, 2007
I changed the type and still doesn't work.. when I try to login after creating new login, it says "Sorry, could not log you in. Wrong login information."

I will try the other.. Thank you!

Originally Posted by macneato View Post
With the password field. Change the type to varchar(25)

As for requesting passwords.

Yes. It can be done.
Ask the user to enter their email address.
select password from your_db where email_address = 'their_address'
Use the mail() function to send the password to the email address.

SQL:
SELECT
dbusers.password
FROM
dbusers
WHERE
(dbusers.email = 'pforgot')

'pforgot' is any name you've given to the form text input. Will write up a full script as soon as i get time. It's monday morning.. Things are a little hectic.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb HTML and CSS Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the HTML and CSS Forum

All times are GMT -4. The time now is 1:16 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC