943,908 Members | Top Members by Rank

Ad:
You are currently viewing page 1 of this multi-page discussion thread
Nov 17th, 2007
-5

To create a registration page and login page

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vinomashwin is offline Offline
1 posts
since Nov 2007
Nov 19th, 2007
0

Re: To create a registration page and login page

You need a server-side script.
Reputation Points: 730
Solved Threads: 181
Nearly a Senior Poster
MidiMagic is offline Offline
3,314 posts
since Jan 2007
Nov 22nd, 2007
1

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

HTML and CSS Syntax (Toggle Plain Text)
  1. <?
  2. // Replace the variable values below
  3. // with your specific database information.
  4. $host = "localhost";
  5. $user = "UserName";
  6. $pass = "Password";
  7. $db = "dbName";
  8.  
  9. // This part sets up the connection to the
  10. // database (so you don't need to reopen the connection
  11. // again on the same page).
  12. $ms = mysql_pconnect($host, $user, $pass);
  13. if ( !$ms )
  14. {
  15. echo "Error connecting to database.\n";
  16. }
  17.  
  18. // Then you need to make sure the database you want
  19. // is selected.
  20. mysql_select_db($db);
  21. ?>

Registration name this file "register.php"

HTML and CSS Syntax (Toggle Plain Text)
  1. <?php
  2.  
  3. // dbConfig.php is a file that contains your
  4. // database connection information. This
  5. // tutorial assumes a connection is made from
  6. // this existing file.
  7. include ("dbConfig.php");
  8.  
  9.  
  10. //Input vaildation and the dbase code
  11. if ( $_GET["op"] == "reg" )
  12. {
  13. $bInputFlag = false;
  14. foreach ( $_POST as $field )
  15. {
  16. if ($field == "")
  17. {
  18. $bInputFlag = false;
  19. }
  20. else
  21. {
  22. $bInputFlag = true;
  23. }
  24. }
  25. // If we had problems with the input, exit with error
  26. if ($bInputFlag == false)
  27. {
  28. die( "Problem with your registration info. "
  29. ."Please go back and try again.");
  30. }
  31.  
  32. // Fields are clear, add user to database
  33. // Setup query
  34. $q = "INSERT INTO `dbUsers` (`username`,`password`,`email`) "
  35. ."VALUES ('".$_POST["username"]."', "
  36. ."PASSWORD('".$_POST["password"]."'), "
  37. ."'".$_POST["email"]."')";
  38. // Run query
  39. $r = mysql_query($q);
  40.  
  41. // Make sure query inserted user successfully
  42. if ( !mysql_insert_id() )
  43. {
  44. die("Error: User not added to database.");
  45. }
  46. else
  47. {
  48. // Redirect to thank you page.
  49. Header("Location: register.php?op=thanks");
  50. }
  51. } // end if
  52.  
  53.  
  54. //The thank you page
  55. elseif ( $_GET["op"] == "thanks" )
  56. {
  57. echo "<h2> Thanks for registering!</h2> ";
  58. }
  59.  
  60. //The web form for input ability
  61. else
  62. {
  63. echo "<form action=\"?op=reg\" method=\"POST\"> \n";
  64. echo "Username: <input name=\"username\" MAXLENGTH=\"16\"> <br /> \n";
  65. echo "Password: <input type=\"password\" name=\"password\" MAXLENGTH=\"16\"> <br /> \n";
  66. echo "Email Address: <input name=\"email\" MAXLENGTH=\"25\"> <br /> \n";
  67. echo "<input type=\"submit\"> \n";
  68. echo "</form> \n";
  69. }
  70. // EOF
  71. ?>

Login name this file "login.php"
HTML and CSS Syntax (Toggle Plain Text)
  1. <?php
  2. session_start();
  3. // dBase file
  4. include "dbConfig.php";
  5.  
  6. if ($_GET["op"] == "login")
  7. {
  8. if (!$_POST["username"] || !$_POST["password"])
  9. {
  10. die("You need to provide a username and password.");
  11. }
  12.  
  13. // Create query
  14. $q = "SELECT * FROM `dbUsers` "
  15. ."WHERE `username`='".$_POST["username"]."' "
  16. ."AND `password`=PASSWORD('".$_POST["password"]."') "
  17. ."LIMIT 1";
  18. // Run query
  19. $r = mysql_query($q);
  20.  
  21. if ( $obj = @mysql_fetch_object($r) )
  22. {
  23. // Login good, create session variables
  24. $_SESSION["valid_id"] = $obj->id;
  25. $_SESSION["valid_user"] = $_POST["username"];
  26. $_SESSION["valid_time"] = time();
  27.  
  28. // Redirect to member page
  29. Header("Location: members.php");
  30. }
  31. else
  32. {
  33. // Login not successful
  34. die("Sorry, could not log you in. Wrong login information.");
  35. }
  36. }
  37. else
  38. {
  39. //If all went right the Web form appears and users can log in
  40. echo "<form action=\"?op=login\" method=\"POST\">";
  41. echo "Username: <input name=\"username\" size=\"15\"><br />";
  42. echo "Password: <input type=\"password\" name=\"password\" size=\"8\"><br />";
  43. echo "<input type=\"submit\" value=\"Login\">";
  44. echo "</form>";
  45. }
  46. ?>

Members Area name this file "members.php", and include on pages that are only for registered users
HTML and CSS Syntax (Toggle Plain Text)
  1. ?php
  2. session_start();
  3.  
  4. if (!$_SESSION["valid_user"])
  5. {
  6. // User not logged in, redirect to login page
  7. Header("Location: login.php");
  8. }
  9.  
  10. // Member only content
  11. // ...
  12. // ...
  13. // ...
  14.  
  15. // Display Member information
  16. echo "<p>User ID: " . $_SESSION["valid_id"];
  17. echo "<p>Username: " . $_SESSION["valid_user"];
  18. echo "<p>Logged in: " . date("m/d/Y", $_SESSION["valid_time"]);
  19.  
  20. // Display logout link
  21. echo "<p><a href=\"logout.php\">Click here to logout!</a></p>";
  22. ?>

logout name this file "logout.php"
HTML and CSS Syntax (Toggle Plain Text)
  1. <?php
  2. session_start();
  3. session_unset();
  4.  
  5. session_destroy();
  6. // Logged out, return home.
  7. Header("Location: index.php");
  8. ?>

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 8:10 am. Reason: typo
Reputation Points: 46
Solved Threads: 48
Posting Pro in Training
macneato is offline Offline
414 posts
since Jun 2007
Nov 22nd, 2007
0

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.
Reputation Points: 46
Solved Threads: 48
Posting Pro in Training
macneato is offline Offline
414 posts
since Jun 2007
Nov 26th, 2007
0

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..
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ViroGen is offline Offline
14 posts
since Nov 2007
Nov 26th, 2007
0

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.
Reputation Points: 46
Solved Threads: 48
Posting Pro in Training
macneato is offline Offline
414 posts
since Jun 2007
Nov 26th, 2007
0

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!

Click to Expand / Collapse  Quote originally posted by macneato ...
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ViroGen is offline Offline
14 posts
since Nov 2007
Nov 26th, 2007
0

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ViroGen is offline Offline
14 posts
since Nov 2007
Dec 1st, 2007
0

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cashu is offline Offline
4 posts
since Nov 2007
Dec 10th, 2007
0

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
prakruti is offline Offline
3 posts
since Dec 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
This thread is currently closed and is not accepting any new replies.
Previous Thread in HTML and CSS Forum Timeline: text moving in rectangular shape
Next Thread in HTML and CSS Forum Timeline: CSS float image and text inline with image





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC