# Login Form



## M-Cheezy (Feb 9, 2007)

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


----------



## knight_47 (Mar 15, 2006)

This can be done in PHP, but depending on how advanced you need the thing to be, you can do a simple:


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


----------



## Chris_E (Feb 16, 2006)

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


----------



## knight_47 (Mar 15, 2006)

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.


----------



## M-Cheezy (Feb 9, 2007)

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.


----------



## namenotfound (Apr 30, 2005)

knight_47 said:


> This can be done in PHP, but depending on how advanced you need the thing to be, you can do a simple:
> 
> 
> ```
> ...


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
$user = ($_POST['user'] === 'YOUR_USERNAME_HERE');
$pass = ($_POST['pass'] === 'YOUR_PASSWORD_HERE');

if ($user AND $pass) {
echo "
[B][SIZE=14]The username and password are correct!![/SIZE][/B]
";
}
else {
echo "
[B][SIZE=14]That is the wrong username and password[/SIZE][/B]
";
}
?>
```


----------



## knight_47 (Mar 15, 2006)

namenotfound said:


> 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:
> 
> 
> ```
> ...


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.


----------



## M-Cheezy (Feb 9, 2007)

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?


----------



## namenotfound (Apr 30, 2005)

The script has the correct combination in it already  And you have to specify the link yourself.


----------



## M-Cheezy (Feb 9, 2007)

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.


----------



## namenotfound (Apr 30, 2005)

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.


----------



## M-Cheezy (Feb 9, 2007)

Alright, I'll save that page for later; I guess you have to buy the database, but that's not my job


----------



## knight_47 (Mar 15, 2006)

M-Cheezy said:


> Alright, I'll save that page for later; I guess you have to buy the database, but that's not my job


No you don't buy databases, you just need to probably buy a host that supports PHP, and MySql, unless you already have one.


----------



## ThaBrudda (Apr 12, 2003)

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  ).

TIA,

ThaBrudda


----------



## namenotfound (Apr 30, 2005)

knight_47 said:


> No you don't buy databases, you just need to probably buy a host that supports PHP, and MySql, unless you already have one.


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)


----------



## M-Cheezy (Feb 9, 2007)

Wow, I had no idea there was this much stuff past html and java. I'm still having trouble doing PC Support and learning how to fix computers. Hehe, guess I got a lot more to learn.


----------



## MMJ (Oct 15, 2006)

Java or JavaScript?

If you know java than you already know most of php, they are very similar.


----------



## knight_47 (Mar 15, 2006)

MMJ said:


> Java or JavaScript?
> 
> If you know java than you already know most of php, they are very similar.


Java is 1000 times more advanced than php! I hated Java in my Computer Science class, don't even remind me!!!


----------



## MMJ (Oct 15, 2006)

knight_47 said:


> Java is 1000 times more advanced than php! I hated Java in my Computer Science class, don't even remind me!!!


Of course it is, so if you know java than you know most of php. 

Than doesn't work the other way around.


----------



## namenotfound (Apr 30, 2005)

I knew someone that took a class in Java. She forgot everything she learned about it. So the class was wasted for her


----------



## MMJ (Oct 15, 2006)

This script can't really do much for you, for example if I have it point to another page (e.g. admin.php) if the user & pass are correct than anybody can access that page (admin.php) directly if they know the link.

I'm going to work on it and see if I can get it to read and place cookies yet keep it simple.


----------

