Computer Programming web Web programming Tips



User Authentication, User Registration Script. PHP

By Sergey Skudaev

Happy Amazon Prime Day July 12 - Exclusive Deals for Prime Members - Start Free 30-Day Trial

I am offering free a complete website with users registration, Authentication and authorization and ability to add comments if you by Learn PHP Programming by Examples. The demo web site has two levels of users: regular user and admin user. Some web pages can be access by all users and some web pages can be accessed by all users.

Additionally, the demo web site http://new-trip.com includes 3 css style files with different color schemas and for 3 columns page layout with web page templates.

You do not have to know PHP programming to use my set of templates. To make your web site capable to register visitors and set to visitors different permissions you have to perform the following steps.





1. Create mail account on your hosting control panel.

How to set email account in your control panel

2. Create MySQL database and database users.

How to create MySQL database in your control panel

3. Create username table in MySQL database using phpMyAdmin. Detailed instruction will be provided.

How to use phpMyAdmin

Your hosting control panel has phpMyAdmin installed and you can use it right away to access you database and create tables. Open SQL window and paste my script included in the usernames.sql.txt file. Click Go button. The usernames table will be created.

Create auth directory in your web site root directory and unzip auth.zip file there. The Root directory is where all your web page files are stored. Usually it is public_html.

4. Edit "connect.php" file. Enter your database name, your user name, your user password created in step 2. Enter your hosting email address created in step 1.

It should looks like that:

<?php
$hostname = "localhost";

$dbuser = "myuser";

$dbpassword = "mypassword";

$dbname = "mydatabase";

$domain_email="webmaster@yourdomain.com";
?>

There should not be any space character after ?>






If you want that your particular web page was accessible only to registered users include the "auth.php" file on the top of this page. See the "protected_template.php" file as example. The web page must have extension .php and not .html.

If you want that your particular web page was accessible only to admin users, include the "adminauth.php" file on the top of this page. See the "admin_template.php" file as example. The web page must have extension .php and not .html.

I included webpagetemplate.php file that is an unsecured page template, the secured_template.php file that is accessible only to registered users and the admin_template.php file that is accessible only to users with the admin role. When your register yourself, you should set role to admin. You can do that in phpMyAdmin. Open username table, find your record and change role from user to admin. All the rest users will have role user and will not have access to admin pages. See how to use phpMyAdmn above.

I include style.css files to control web page design and layout and JavaScript files for user input validation.

Test your web site user registration. Create your account, login and password. Email with activation link will be sent to your user email. Open email and click the activation link. Your account will be activated. Log into your web site. Try to access pages with limited permissions before you login and after. Try to login as a regular user and as an admin.

If you cannot create database and usernames table or have any question, feel free to contact me by email: master@configure-all.com.

You should be aware that even though your web site users use login and password to access certain web pages it does not mean that that pages are secured. The difference between secure and unsecure connection depends on what kind Hypertext Transfer Protocol is used.

There are HTTP and HTTPS transfer protocols. If web site use https transfer protocol it means that data, which is transferred between web server and client browser is encrypted.

If http protocol is used, it means that data is not encrypted and can be eavesdropped. However, you can use unsecure HTTP protocol with login and password for such web sites as message boards, social sites etc. Facebook.com, twitter.com and many others web site use HTTP. They have some kind of protection that is enough for them.

If you are not a bank, you can use HTTP protocol with login and password. You even can use unsecure HTTP for business site. For example, you may display your products or services on unsecure page, but when user needs to enter payment he or she is redirected to secured page. My website uses HTTP protocol. It is not secured, but I use PayPal secured page to accept payment.

Hosting company I use and recomend!

1. Fatcow.com I use it for www.configure-all.com, www.hardstuffez.com and www.healthstairs.com
40% off at FatCow!

Affiliate Disclosure: I may get comission, when you purchase products or services through links on my website.


Subscribe to our mail list to receive free code examples.

Comments

No comments yet.

Add Comment

* Required information
(never displayed)
 
Smile Sad Huh Laugh Mad Tongue Crying Grin Wink Scared Cool Sleep Blush Unsure Shocked
 
1000
Enter the third word of this sentence.
 
Enter answer:
Captcha
Refresh
 
Enter code:
 
Notify me of new comments via email.
 
Remember my form inputs on this computer.
 
I have read and understand the privacy policy. *
 
I have read and agree to the terms and conditions. *
 
 
Powered by Commentics

My eBooks on Amazon.com

Learn C++ Programming By Examples

Learn SQL Programming By Examples

Learn PHP Programming by Examples

Visual Basic Programming By Examples

How to Build Your Own Web Site from Scratch