| CREATE A MEMBERSHIP LOGIN ACCOUNT |
In this section I am going to show you how to create a Membership Login area for your website, using PHP Scripts, so that you can have your visitors
sign up for a Membership Account. The php scripts are divided into Registration, Email Activation, Account Login, Forgot Password, Account Logout and
so on to give your website and its visitors the complete membership experience.....all for FREE!
Begin by downloading the php scripts, which are contained inside a zip file, from
http://php-login-script.com/index2.htm.
Once the zip file (php-login-script-v1.0.zip) has been downloaded,
into your DOWNLOADS folder for example, extract (unzip) it. If you use Windows Vista to extract the zip file you will be left with a folder called
php-login-script-v1.0 inside the DOWNLOADS folder, and inside that folder will be a sub-folder that is also called php-login-script-v1.0. In which case,
make sure you are inside the sub-folder called php-login-script-v1.0. Regardless of how you extract the zip file, and to where, you will still have a
folder with the following files inside it.
The first thing you need to do is create a MySQL Database for these membership scripts. Read the How To Create A MySQL Database section if you do not know how to do this. Give the mysql database a simple name like database or members. Remember. Your control panel might give your mysql database a prefix that is named after your website user name. For example. I have created a mysql database called database but it is prefixed with website1_ so it is now known as website1_database. The mysql database is very important because it is going to store information about your members.
After creating your mysql database and mysql database user name you need to double click on the dbc.php file (Fig 1.0 above) and change the mysql database connection details inside it. Once you have done that simply re-save the file. Click on the FILE menu and then select the SAVE menu-item. This will save the file to the same folder, same file but now with your modifications inside it. Fig 1.1 shows the original, empty template, mysql database connection details for the dbc.php file and Fig 1.2 shows my proper mysql database connection details for the dbc.php file.
With the dbc.php file re-saved with your modifications inside it the next thing to do is create some Table information for the mysql database. Read the How To Create A MySQL Database Table section if you do not know how to create a mysql database table.
A table is basically a list of records (rows of data) that consist of the same Fields (Headings), with each field normally having
a different Data Entry. For example. Each record could have fields called TITLE, NAME and EMAIL ADDRESS whereby you would then fill in the Data Entry for each
field. So the data (field) entries for record 1 could be Mr, John White and john@websitecreationhelp.com and the data (field) entries for record 2 could
be the same as record 1 or they could be different (i.e. Mrs, Jane Smith, jsmith@hotmail.com). Either way. The fields in each record, for that specific
table, are always the same (i.e. TITLE, NAME and EMAIL ADDRESS). So if you create two tables (i.e. members and guests), the records in each table can
have the same fields or just a couple of fields the same (because they are two separate tables). For example. The members table could have records inside
it with fields TITLE, NAME and EMAIL ADDRESS whereas the guests table could have records inside it with fields TITLE, NAME, ADDRESS, POSTCODE.
MySQL has a command that creates a table for you, called CREATE TABLE. It allows you to specify each field's name as well as it field type (i.e. INT,
TEXT, etc). To create a table open a text editor such as Notepad, type out your Table command and then save that text file as a .sql (text) file. From
there. Use your myphpadmin control panel to either IMPORT that table.sql file into your mysql database or copy and paste it into the SQL console window.
Both of these methods are explained in the How To Create A MySQL Database Table
section. Here is the table you should create for the php scripts to work - You can modify the fields if
you want to but for this example use the original, USERS, table.
In the above USERS Table you can modify the following fields (field names) if you want to, but this may mean altering some of the other php scripts in order for everything to work properly. FULL_NAME, USER_NAME, USER_PWD, USER_EMAIL, ACTIVATION_CODE, JOINED, COUNTRY and USER_ACTIVATED can be modified but I would only recommend renaming FULL_NAME, JOINED and COUNTRY if need be. And even then, I would only modify them slightly (i.e. NAME, DATE_JOINED and AREA). You can also delete and add fields of course. So you could add `user_nickname` varchar(200) collate latin1_general_ci NOT NULL default '', and `membership_rating` varchar(200) collate latin1_general_ci NOT NULL default '', for example. I would definitely recommend limiting the maximum space allocated for the text fields. Change 200 to 100 for example because you do not want wasted space bloating up your mysql database. In other words. Even if you do not fill in a field's data entry it will still have 200 spaces (trailing bytes) allocated for it.
At this point you should have a mysql database set up (i.e. website1_database) that contains the above USERS table; and a dbc.php file that contains the mysql database connection details for that mysql database. If so, the next thing to do is upload the membership php script files to your public_html (website) folder. An example of how to connect to your public_html folder is given in the How To Connect To A Website Folder Via FTP section. Once you are connected to your web space and have the public_html folder open simply Copy & Paste the following files into it, from the sub-folder called php-login-script-v1.0.
As you can see. Not all of the files are needed. Out of the four .png (image) files for example only bg1.PNG is needed. It is the main background image for the AUTHENTICATION CODE edit box. The other three .png files are just alternative image examples. Therefore. You could create your own background image and name it bg1.PNG, but you should find the original bg1.PNG image suitable. The README.txt file is another file that is not needed, which means the rest of the files are needed. So copy all of the files over to your public_html folder except the bg2.PNG, bg3.PNG, bg4.PNG and README.txt files.
With the files copied all you have to do now is invite visitors to join your Membership Scheme. Give them a link to your login.php page or register.php page and give them access to your Members Only web pages, downloads folder and so on.
With these membership scripts, and membership scripts in general, there is always a piece of "magic code" that must be inserted into each web page's html code in order to protect it from non-members. The "magic code" only allows people with a valid User Name & Password to view the web page's content. With these particular membership scripts you must insert the following php code at the very top of each web page you want protecting.
Note here. I have modified the original code. It used die ("Access Denied"); to take the non-member to a blank web page that just stated ACCESS
DENIED, which looks ugly and unprofessional. This is not a dig at the author. Quite the opposite. I am pointing out that you have to remember; it is not
the author's job to supply you with alternative code. They have kindly given you the foundation code which you can modify for your own requirements. And
that is what I have done here. I have used header("Location: login.php");, instead die ("Access Denied");, to divert the non-member to the
login.php file. This means any visitor who tries to directly access a members only web page, without logging in first, will automatically be redirected
to the login.php web page (if they like it or not!).
Another thing to note here is that every one of your web pages, that have the magic php code inside them, must end with the .php file name extension. They
can be created as HTML (.html) files (web pages) but when using these membership scripts live on the internet your html files, now with the magic php
code inside them, must have their file name extensions renamed to .php (before going live on the internet).
| TWEAKING THE MEMBERSHIP PHP SCRIPTS |
With the above you should have the membership scripts working fine. However. As said above; do not expect an author in general to cater totally for you and your website requirements. As long as their foundation code does what it is supposed to do you cannot ask for anything more, especially when it is FREE. In this case the php scripts provide your web pages with code needed to block off non-members and membership scripts for registration, forgotten password and so on. If you need more script functionally and/or help you can use the Support Forum. You could ask someone if they know how to implement your desired functionality for example. Below is some general tweaking and advice for you.
If you have changed the name of the actual login.php file, to index.php for example, you would need to change login.php in the following script files (to index.php for example). activate.php, logout.php and settings.php. One reason for changing login.php to index.php is when you want your index web page, and normally the rest of your website, to be under membership.
In the register.php file you can take control of the activation process. By changing the Mail() function you can have the activation email sent to you instead of the person wanting to register. So they will have to wait for your approval. And because you are the one who has to activate the registration, via the activation link inside the email, you can approve or deny a particular email address or a particular domain (i.e. you do not want Hotmail visitors.....perhaps because your perception of them is "They always want FREE stuff")?!!
The above is highlighting the code section you need to change. The Mail() function. You can change the email address to your own by changing mail($_POST['email'] , into mail("yourname@yourdomain.com", (i.e. mail("john@websitecreationhelp.com",). You can also make the subject more meaningful. Instead of Login Activation you could use Activation Required for example. And the same with FROM. Instead of "From: \"Auto-Response\" <notifications@$host>\r\n" you could use "From: \"New Member Registration\" <noreply@yourdomain.com>\r\n".
If you are not happy when a script uses the die() command, to display an error message on a blank window for example, you may be able to substitute that
die() command with a header() command. This would enable you to redirect the error message. For example. You should generally leave a mysql() error
message such as die(mysql_error()); with the die() command, so that it can exit the script, but where you see an error message like
die("ERROR: Password does not match or empty.."); you can redirect it using the header() command. You could use something like
header("Location: register.php?msg=DIFFERENT PASSWORDS"); instead. This would redirect (send) the error message to the register.php web page, but
you could send it to another web page if you wanted to, which then displays the error message DIFFERENT PASSWORDS in red on the same register web page.
Here is the code that does that: <?php if (isset($_GET['msg'])) { echo "<font color='red'><b>$_GET[msg]</b></font>"; } ?>.
If you want to redirect a successful login, to go to your members.php web page instead of the myaccount.php web page, simply edit the
header("Location: myaccount.php"); line in the login.php script.
Remember. These kind of php scripts are like GOLD. Many companies and websites out there charge a small fortune for such membership scripts. So download these php scripts while they are still available. It is not uncommon for programs and scripts to be freeware (FREE) and then months/years later become shareware or commercial because a company has paid the author a small fortune for copyright ownership.
All HTM, CSS, PHP and MySQL files in the websitecreationhelp.com folder and its sub-folders are (c) John White, 2009. All Rights Reserved. Email: John