So, making a 'member' section on a site consists out of five parts:
1. Setting up the MySQL database with a username and a password.
2. Connecting the site to the database.
3. Making a login page.
4. Lock the pages you want to keep from the open public.
5. Making a logout page.
1. Setting up the MySQL database with a username and a password.
Open up PHP MyAdmin (that's the graphical MySQL database made with PHP). You will probably find it in the user section of your hosting.
If you don't already have a database, add one under Create new database.
Let's name it Login.
Then you 'open' up the database by clicking on it in the left bar.
You'll see a summary of your database. Under the summary you see a text field with Create new table on database ..., name it login and fill in 3 in number of fields.
A new page opens up. You'll see al lot of text fields.
There are 3 columns, and 10 rows.
If there are 3 rows and 10 columns you swap the words in this explanation.
Fill in these things:
1st column, 1st row: id
2nd column, 1st row: username
3rd column, 1st row: password
1st column, 2nd row: leave it as it is
2nd column, 2nd row: select varchar
3rd column, 2nd row: select varchar
1st column, 3rd row: leave it as it is
2nd column, 3rd row: 250
3rd column, 3rd row: 32
1st column, 9th row: check the checkbox
Then click on save in the right bottom corner.
You have just created the login table!
Now you'll have to populate it with information.
Click on the name of the table in the left bar.
Click on insert in the tabs.
First, you'll need to code the password for extra safety.
Go to
http://www.tech-faq.com/md5-generator.shtml fill in the prefered password click on generate md5 hash and copy the result.
e.g. the md5 hash of password is: 5f4dcc3b5aa765d61d8327deb882cf99
Fill in these things:
leave id open
fill in the preferred username in username
fill in the md5 hash of your password
click on go and you're done with the hardest part!
2. Connecting the site to the database.
Open up Dreamweaver.
Click on site and then manage sites...
Select the site and click on edit.
Go through the setup wizard till the point where you can choose to use a server technology.
Click on yes and select PHP MySQL.
Keep on clicking on next till your done with the wizard and click on done in the site management.
Your site is ready to connect to the database!
Click on window and then on databases.
A new window shows up. Click on the plus icon in the top left corner of the new window and select mysql connection.
Fill in these thins:
Name of connection: connLogin
MySQL-server: localhost
Username: the username of your MySQL server, look it up in the faq of your hosting or send an email to them if you don't know this
Password: the password of your MySQL serer.
Database: click on select and select the databse
Then click on Ok.
Your site is connected to the database!
3. Making a login page.
Add a new page in dreamweaver, call it login.php
Add a form, this is the code:
HTML:
<form id="form1" name="form1" method="post" action="">
<label>
<input type="text" name="username" id="username" />
</label>
<br /><br />
<label>
<input type="text" name="password" id="password" />
</label>
<br />
<label>
<input type="submit" name="submit" id="submit" value="Submit" />
</label>
</form>
Then click on the plus icon in the server behaviors palette.
Click on User Authentication and the on Log In User.
Fill in:
Username field: select username
Password field: select password
validate using connection: select connLogin
table: select login
username column: select username
password column: select password
If login succeeds, go to: members.php
If login fails, go to: check go to previous url (if it exists)
Restrict access based on: Username and Password.
Click on OK.
No go to the code mode and scroll to the top of all the code.
As you see, dreamweaver added a lot of php code in your page.
You'll need to add these lines of code at the top of the page, before all the <?php tags.
PHP:
<?php
if(isset($_POST['password'])) {
$_POST['password'] = md5($_POST['password']);
}
?>
Save the file.
The login page is done!
4. Lock the pages you want to keep from the open public.
Add a new file in dreamweaver, call it members.php.
Click on the plus icon in the server behaviors palette and click on User Authentication and then on Restrict access to page.
Fill in:
Restrict based on: Username and password
If acces denied, go to: login.php
Click on OK, the members page is done!
5. Making a logout page.
Add some text to the members page like log out. (add it where you want the log out link to be)
Select it and click on the plus icon in the server behaviors palette.
Then click on User Authentication and then on Log out user.
fill in:
Log out when: link clicked
When done, go to: your homepage
The members section is done!
If you want to add extra pages to the members section, just add a new page with .php at the end and add the Restrict access behavior with the given information!
Please tell me if you didn't get something.