To create a registration page and login page

Reply

Join Date: Nov 2007
Posts: 1
Reputation: vinomashwin is an unknown quantity at this point 
Solved Threads: 0
vinomashwin vinomashwin is offline Offline
Newbie Poster

To create a registration page and login page

 
-1
  #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
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 3,193
Reputation: MidiMagic has a spectacular aura about MidiMagic has a spectacular aura about 
Solved Threads: 162
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Posting Sensei

Re: To create a registration page and login page

 
0
  #2
Nov 19th, 2007
You need a server-side script.
Daylight-saving time uses more gasoline
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 211
Reputation: macneato is an unknown quantity at this point 
Solved Threads: 18
macneato's Avatar
macneato macneato is offline Offline
Posting Whiz in Training

Re: To create a registration page and login page

 
0
  #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

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
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 211
Reputation: macneato is an unknown quantity at this point 
Solved Threads: 18
macneato's Avatar
macneato macneato is offline Offline
Posting Whiz in Training

Re: To create a registration page and login page

 
0
  #4
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 Quick reply to this message  
Join Date: Nov 2007
Posts: 14
Reputation: ViroGen is an unknown quantity at this point 
Solved Threads: 0
ViroGen ViroGen is offline Offline
Newbie Poster

Re: To create a registration page and login page

 
0
  #5
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 Quick reply to this message  
Join Date: Jun 2007
Posts: 211
Reputation: macneato is an unknown quantity at this point 
Solved Threads: 18
macneato's Avatar
macneato macneato is offline Offline
Posting Whiz in Training

Re: To create a registration page and login page

 
0
  #6
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 Quick reply to this message  
Join Date: Nov 2007
Posts: 14
Reputation: ViroGen is an unknown quantity at this point 
Solved Threads: 0
ViroGen ViroGen is offline Offline
Newbie Poster

Re: To create a registration page and login page

 
0
  #7
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 Quick reply to this message  
Join Date: Nov 2007
Posts: 14
Reputation: ViroGen is an unknown quantity at this point 
Solved Threads: 0
ViroGen ViroGen is offline Offline
Newbie Poster

Re: To create a registration page and login page

 
0
  #8
Nov 26th, 2007
That would be great! I am still learning and developers like you help in this learning process.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 4
Reputation: cashu is an unknown quantity at this point 
Solved Threads: 0
cashu cashu is offline Offline
Newbie Poster

Re: To create a registration page and login page

 
0
  #9
Dec 1st, 2007
i had the same problem.
thanks
cashu
http://tech-unite.com/forum/viewtopic.php?f=5&t=10
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 3
Reputation: prakruti is an unknown quantity at this point 
Solved Threads: 0
prakruti prakruti is offline Offline
Newbie Poster

Re: To create a registration page and login page

 
0
  #10
Dec 10th, 2007
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
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC