DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   HTML and CSS (http://www.daniweb.com/forums/forum143.html)
-   -   To create a registration page and login page (http://www.daniweb.com/forums/thread97183.html)

vinomashwin Nov 17th, 2007 1:51 pm
To create a registration page and login page
 
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

MidiMagic Nov 19th, 2007 9:58 pm
Re: To create a registration page and login page
 
You need a server-side script.

macneato Nov 22nd, 2007 8:08 am
Re: To create a registration page and login page
 
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

macneato Nov 22nd, 2007 8:14 am
Re: To create a registration page and login page
 
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.

ViroGen Nov 26th, 2007 2:04 am
Re: To create a registration page and login page
 
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..

macneato Nov 26th, 2007 3:34 am
Re: To create a registration page and login page
 
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.

ViroGen Nov 26th, 2007 3:38 am
Re: To create a registration page and login page
 
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!

Quote:

Originally Posted by macneato (Post 478284)
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.


ViroGen Nov 26th, 2007 12:56 pm
Re: To create a registration page and login page
 
That would be great! I am still learning and developers like you help in this learning process.

cashu Dec 1st, 2007 3:18 pm
Re: To create a registration page and login page
 
i had the same problem.
thanks
cashu
http://tech-unite.com/forum/viewtopic.php?f=5&t=10

prakruti Dec 10th, 2007 11:03 am
Re: To create a registration page and login page
 
hey hi,dis is prakruti i too have same pro...i m creating a website for which i require registration page and login page.I have referred to the reply given in dis forum.But i guess dis code uses mysql as database but my database is DB2 frm IBM..plz can u suggest me how to design the registration and login webpage using DB2 as database.I would be very grateful if anyone helps me.
thanking u

ViroGen Dec 29th, 2007 4:11 pm
Re: To create a registration page and login page
 
Please help me with code for users who forget their password and need to ask for it. I have been trying and failing badly!

ViroGen Dec 29th, 2007 4:34 pm
Re: To create a registration page and login page
 
Is there a way to make any of these entry lines required?

ViroGen Dec 29th, 2007 5:13 pm
Re: To create a registration page and login page
 
I need help.. I can't seem to write the code so someone can request forgotten password. Please help me with this code. Also, is there a way to make it so that the input fields are required?

Also, how can I make them retype their password when they are registering? If the retype does not match, then tell them somehow.

Thank you so much for your help. I am still learning and this is a huge help!

I am sorry about the repost of questions. I failed to see my posts and noticed then they were on page 2 of this discussion.

ViroGen Dec 29th, 2007 6:41 pm
Re: To create a registration page and login page
 
Is there a way to have a drop down list for the input fields?

ViroGen Dec 29th, 2007 8:01 pm
Re: To create a registration page and login page
 
Figured this one out.. !!

ViroGen Jan 12th, 2008 2:50 am
Re: To create a registration page and login page
 
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

ViroGen Jan 12th, 2008 2:50 am
Re: To create a registration page and login page
 
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!

ViroGen Jan 12th, 2008 2:53 am
Re: To create a registration page and login page
 
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?

MidiMagic Jan 12th, 2008 1:24 pm
Re: To create a registration page and login page
 
Your script needs to check these things. That's what if statements are for.

Look at the contents of the fields, and send the user back to the form if they are not filled in.

Look for an existing user with that login before registering a new user.

ViroGen Jan 12th, 2008 1:56 pm
Re: To create a registration page and login page
 
The problem is that I am new at this and I have been trying for a few weeks to figure it out. Is there any way you or anyone can help me with this code? I don't expect people doing my work, especially without my own trial and error, but I am at a loss here and need help. Any help would be great. Code is based on code from this thread/site. My email address is general@cybrtech.net if you, or anyone, would be so kind as to help me. I can try to compensate somehoe.

macneato Jan 15th, 2008 7:36 am
Re: To create a registration page and login page
 
Sorry viro. Been on vacation.. In mozambique and ended up getting a bad case of malaria. Nevertheless. I'm back and feeling in quite a good mood -haha, must be cause im alive. So, figured im gonna write up a complete, new script and zip it up all nicely for you. Expect it soon.

macneato

ithelp Jan 15th, 2008 10:08 am
Re: To create a registration page and login page
 
Quote:

Originally Posted by ViroGen (Post 500380)
I need help.. I can't seem to write the code so someone can request forgotten password. Please help me with this code. Also, is there a way to make it so that the input fields are required?

Also, how can I make them retype their password when they are registering? If the retype does not match, then tell them somehow.

Thank you so much for your help. I am still learning and this is a huge help!

I am sorry about the repost of questions. I failed to see my posts and noticed then they were on page 2 of this discussion.

You can use ready made forum software like phpBB which will save you from this kind of coding problem.

macneato Jan 15th, 2008 10:26 am
Re: To create a registration page and login page
 
But thats a board. Which means you limited in terms of templates and many other factors.

dottomm Feb 8th, 2008 6:24 pm
Re: To create a registration page and login page
 
I too am getting the "Sorry, could not log you in. Wrong login information." error. I've changed the password field to VARCHAR 25.

Additionally, when I do the register.php page There is no error message OR THank you message. Can anybody tell me if they have been able to get this script to work. I feel I am so close.

thanks in advance

jrb4562 Apr 18th, 2008 10:38 pm
Re: To create a registration page and login page
 
Ok guys this is a great post but I have absolutly never dealt with php before how do i put this file into my HTML code so that I can register users. I have tried stuff I found on google but nothing worked I would really thank you if you could help

ViroGen Apr 18th, 2008 10:41 pm
Re: To create a registration page and login page
 
Email me if you want help.

<snipped>

ViroGen Oct 9th, 2008 11:07 am
Re: To create a registration page and login page
 
Any new help anyone can provide to help me with users needing help getting their login and password info sent to them if they forget it?

Secret- Dec 29th, 2008 1:51 pm
Re: To create a registration page and login page
 
what u mean with ''Create a new file and name it dbConfig.php" ??

kanaku Dec 29th, 2008 5:04 pm
Re: To create a registration page and login page
 
Quote:

Originally Posted by Secret- (Post 766653)
what u mean with ''Create a new file and name it dbConfig.php" ??

Open a text editor (like notepad) and copy the code into it. Then save the file as dbConfig.php.

Secret- Dec 29th, 2008 6:07 pm
Re: To create a registration page and login page
 
how can I activate or something on my website??

kanaku Dec 29th, 2008 6:25 pm
Re: To create a registration page and login page
 
First, make sure that your site allows you to use php and gives you database access (usually mySQL).

When you finished making the files as instructed here, you have to upload those files to your site using FTP or whatever filemanager comes with your hosting package.

Secret- Dec 30th, 2008 7:03 am
Re: To create a registration page and login page
 
if i want to register on my website this comes :


PHP Error Message

Warning: mysql_pconnect() [function.mysql-pconnect]: Access denied for user 'UserName'@'localhost' (using password: YES) in /home/a4497797/public_html/dbConfig.php on line 12

Free Web Hosting
Error connecting to database.
PHP Error Message

Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'nobody'@'localhost' (using password: NO) in /home/a4497797/public_html/dbConfig.php on line 20

Free Web Hosting

PHP Error Message

Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in /home/a4497797/public_html/dbConfig.php on line 20

Free Web Hosting

PHP Error Message

Warning: mysql_query() [function.mysql-query]: Access denied for user 'nobody'@'localhost' (using password: NO) in /home/a4497797/public_html/register.php on line 39

Free Web Hosting

PHP Error Message

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/a4497797/public_html/register.php on line 39

Free Web Hosting

PHP Error Message

Warning: mysql_insert_id() [function.mysql-insert-id]: A link to the server could not be established in /home/a4497797/public_html/register.php on line 42

Free Web Hosting
Error: User not added to database.

kanaku Dec 30th, 2008 8:46 am
Re: To create a registration page and login page
 
Oh... there's something wrong with the details (or constants) you specified in your dbConfig.php file. This is the code provided in the 1st page of this thread (with comments):

<?
// 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);
?>

The details in red are provided by your host. Most likely, you won't be changing
$host = "localhost";
but you need the
$user, $pass, and $db
. Unfortunately, I can't get that for you since only you are supposed to know your password. The username ($user) and database name ($db) can be requested from your host.

You can't just guess values for that. Ask your host for those details. The script will work fine once you get those values.

Or if you use cpanel, I might be able to guide you into setting up a database.

Secret- Dec 30th, 2008 10:56 am
Re: To create a registration page and login page
 
Soo i need to change ;

$host = "localhost";
$user = "UserName"; << My UserName?
$pass = "Password"; << My Password?
$db = "dbName"; << My Database?

kanaku Dec 30th, 2008 11:45 am
Re: To create a registration page and login page
 
Quote:

Soo i need to change:
$host = "localhost";
$user = "UserName"; << My UserName?
$pass = "Password"; << My Password?
$db = "dbName"; << My Database?

Yup. (Don't post the username and password values here though!)

Secret- Dec 31st, 2008 7:32 am
Re: To create a registration page and login page
 
Okay thanks i will add you reputation ;)

Secret- Dec 31st, 2008 7:54 am
Re: To create a registration page and login page
 
Dude i did ,, but now i get this :


PHP Error Message

Warning: mysql_pconnect() [function.mysql-pconnect]: Access denied for user 'a4497797'@'localhost' (using password: YES) in /home/a4497797/public_html/dbConfig.php on line 10

Free Web Hosting
Error connecting to database.
PHP Error Message

Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'nobody'@'localhost' (using password: NO) in /home/a4497797/public_html/dbConfig.php on line 18

Free Web Hosting

PHP Error Message

Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in /home/a4497797/public_html/dbConfig.php on line 18

Free Web Hosting
Username:
Password:
Email Address:

Secret- Dec 31st, 2008 8:12 am
Re: To create a registration page and login page
 
soo it will like this ( it's a example) :

$host = "localhost";
$user = "Kevin";
$pass = "123456";
$db = "mysqladmin";

it's correct?

kanaku Dec 31st, 2008 8:50 am
Re: To create a registration page and login page
 
Wait... why are you connecting twice? (In line 10 and in line 18 of your dbConfig.php file)... Did you comment out the sample code properly?

And as I said, as long as the details/values are correct, you should be able to connect!

By the way, mysqladmin is most likely NOT your database name. It's something you can use to create databases and tables...

Can you post your dbConfig.php file? Be sure to comment out the values like this:
<?
// Replace the variable values below
// with your specific database information.
$host = "XXXXXXXX";
$user = "XXXXXXX";
$pass = "XXXXXXXX";
$db  = "XXXXXX";


// 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);
?>

Because I think you've accidentally made two sets of connection variables in your config file (thus the double-connection error).

Secret- Dec 31st, 2008 10:15 am
Re: To create a registration page and login page
 
K i post my dbConfig.php here it is :

<?
[COLOR="Red"]$host = "XXXXX";
$user = "XXXXXX";
$pass = "XXXXX!";
$db  = "XXXXXX";[/COLOR]

// 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);
?>


Btw the "XXX'S" are NOT MY REAL DETAILS


All times are GMT -4. The time now is 3:43 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC