1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Login Form

Discussion in 'Web Design & Development' started by M-Cheezy, Feb 9, 2007.

Thread Status:
Not open for further replies.
Advertisement
  1. M-Cheezy

    M-Cheezy Thread Starter

    Joined:
    Feb 9, 2007
    Messages:
    7
    Hello. I'm a senior in high school and am in a Web Design 3 class.

    I just received a new project from my teacher: I need to help another teacher create a website. But he wants a login form so you would need a username and password to join his site. I have the basic code for a login form but I do not know what to do from that point. I guess I'm suppose to set a destination for the form. (If anybody knows what I'm trying to say:( ) Can somebody give me some HTML coding for that?

    Thanks.
    M-Cheezy
     
  2. knight_47

    knight_47

    Joined:
    Mar 14, 2006
    Messages:
    941
    This can be done in PHP, but depending on how advanced you need the thing to be, you can do a simple:

    PHP:
    <?php
    if ($_POST['Submit'] AND $_POST['pass'] == "admin")
    {
    echo 
    "welcome to the password protected page";
    }
    else
    {
    echo 
    "get out of here!";
    }
    ?>
     
  3. Chris_E

    Chris_E

    Joined:
    Feb 16, 2006
    Messages:
    360
    I found a simple chunk of code on dynamicdrive by a guy called Rob Heslop.

    Visit this link:

    http://www.dynamicdrive.com/dynamicindex9/password.htm

    The page is very easy to understand and allows you to put a few lines in your webpage and then go off to a different web page depending on what the username and password both are.

    Hope its useful for you too.

    Chris
     
  4. knight_47

    knight_47

    Joined:
    Mar 14, 2006
    Messages:
    941
    Just be careful with Javascript password protection, since it is client side, it is very easy to hack or bypass. PHP or using your .htaccess file would be much better.

    Depending on what your trying to password protect, if it something important or sensitive, you should NOT use javascript.
     
  5. M-Cheezy

    M-Cheezy Thread Starter

    Joined:
    Feb 9, 2007
    Messages:
    7
    Thank you for your help. I don't completely understand the assignment, as I am only used to working out of an HTML book. I"ll add the code to my page and try to figure out how everything works.
     
  6. namenotfound

    namenotfound

    Joined:
    Apr 30, 2005
    Messages:
    3,012
    Doesn't he want username AND password? You're only offering password. If you look here you can see I use both username and password. Here's the code:

    PHP:
    <?php
    $user 
    = ($_POST['user'] === 'YOUR_USERNAME_HERE');
    $pass = ($_POST['pass'] === 'YOUR_PASSWORD_HERE');

    if (
    $user AND $pass) {
    echo 
    "<h2>The username and password are correct!!</h2>";
    }
    else {
    echo 
    "<h2>That is the wrong username and password</h2>";
    }
    ?>
     
  7. knight_47

    knight_47

    Joined:
    Mar 14, 2006
    Messages:
    941
    It was just an example for him to modify so it can fit his needs. But yeah, your example would have been better to start with.
     
  8. M-Cheezy

    M-Cheezy Thread Starter

    Joined:
    Feb 9, 2007
    Messages:
    7
    Alright, so when the username and password are put in, how do you get the site to remember the correct combination and where would the link go to? Do I need to set up a page specifically for that?
     
  9. namenotfound

    namenotfound

    Joined:
    Apr 30, 2005
    Messages:
    3,012
    The script has the correct combination in it already :D And you have to specify the link yourself.
     
  10. M-Cheezy

    M-Cheezy Thread Starter

    Joined:
    Feb 9, 2007
    Messages:
    7
    Okay, thank you. How about like...a "register for username" thingy, what if I put that link on, which code would I use to let them register? I already have a form complete to type in a username, password, e-mail, etc. I don't know what link to put there. Once I have most of the basic code put together, then I'll post it on here to see if I've done it right. It'll probably be another month before I get it all together though.
     
  11. namenotfound

    namenotfound

    Joined:
    Apr 30, 2005
    Messages:
    3,012
    Well for that you'd most likely would want to use a database. That way when they select their desired username and password, it's stored in the database.
     
  12. M-Cheezy

    M-Cheezy Thread Starter

    Joined:
    Feb 9, 2007
    Messages:
    7
    Alright, I'll save that page for later; I guess you have to buy the database, but that's not my job :D
     
  13. knight_47

    knight_47

    Joined:
    Mar 14, 2006
    Messages:
    941
    No you don't buy databases, you just need to probably buy a host that supports PHP, and MySql, unless you already have one.
     
  14. ThaBrudda

    ThaBrudda

    Joined:
    Apr 12, 2003
    Messages:
    73
    But this is what I am looking for too. (I actually logged on to ask specifically about this topic.)

    I have a website that I am hosting on 1and1. It has protected directories, mySQL databases, .htaccess, and can run php scripts.

    I want to set up a Member's Area and do the following:

    1. Require a username and password for access, unique to each user. I need a form for them to fill out, with their info and requested user name and password (that I guess I would store in a mySQL database on the server, right?).

    2. Require authentication or authorization from me to access the area - meaning I want to know who I am giving access to.

    From reading this thread, I gather that I will need to us php and a mySQL database. 1and1's FAQ's and tutorials on how to do this are woefully lacking.

    What sites or books would you recommend for me to learn how to do this? (Something that does not assume that I am a mySQL or php whiz would be very helpful :D ).

    TIA,

    ThaBrudda
     
  15. namenotfound

    namenotfound

    Joined:
    Apr 30, 2005
    Messages:
    3,012
    It depends on his host. Some offer a database as an upgrade (php with no database for a basic plan).

    But also, you could store the user/pass in a flat file type of database (.txt file)
     
  16. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/542553

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice