NEW v2.3! is released!
A simple home made PHP/MySQL login script to protect your web page content from spam and bot registrations so that only registered users can view the content of your site.. It is free of charge and you can use it on any commercial or personal projects!
Advertisers
Here is how you install the script in your website.
1. MySQL database setup
(i) Create database table
Download and unzip the php login script and you can import the whole dbsql.sql or open the file in notepad and copy the lines and paste into the SQL of database. It will create users table and your admin login.
If you have cpanel you can access phpmyadmin directly this way - point your browser to http://domain.com:2082/3rdparty/phpMyAdmin/
(ii) Database settings
Open dbc.php and set values inside the quotes for your mysql settings.
- database name
- database user
- database password
you will get these information from your hosting provider. Make sure you give full access rights to the database user. If you have cpanel, just login and create database and database user.
example:
define ("DB_HOST", "xxxxx"); // set database
host
define ("DB_USER", "xxxx"); // set database user
define ("DB_PASS","xxxx"); // set database password
define ("DB_NAME","xxxx"); // set database name
3. Setting up reCaptcha for your Script
(i) Download recaptcha php library (http://recaptcha.net/plugins/php/), unzip and copy the single php file recaptchalib.php into login script folder. This is very important, without which the login script will not work
(ii) Go to recaptcha.net,
register a free account, and you will get public and private keys. Make a note
of that and set it here inside dbc.php
$publickey = "xxxxxxxxxxxxxxxxxxxxxxxxxxx"
$privatekey = "xxxxxxxxxxxxxxxxxxxxxxxxx";
3. Configuration settings
Open dbc.php and you have to configure the php login script.
(i) Automatic or Manual registration
/* Registration Type (Automatic or Manual)
1 -> Automatic Registration (Users will receive activation code and they
will be automatically approved after clicking activation link)
0 -> Manual Approval (Users will not receive activation code and you will
need to approve every user manually)
*/
$user_registration = 1; // set 0 or 1
(ii) Other Settings (optional only)
These are the other settings in the script if you want you can change it like cookie expiry time, specify admin levels and much more..
define("COOKIE_TIME_OUT", 10); //specify cookie
timeout in days (default is 10 days)
define('SALT_LENGTH', 9); // salt for password
4. Integrate to your website
I have left spaces for header,footer inside each of the pages. You can place there logos, footer or whatever you want depending on your website.
5. Thank you page.
Upon registering, the users will be taken to thankyou.php page and you can customize it to whatever that suits your needs
6. Login protect a new page
Lets say you have a new page page1.php, and you want only the logged in users to access it. To get this done, just add this one line of code and it should be VERY TOP of your page1.php. Any other html code or php code should be below it.
<?php
include 'dbc.php';
page_protect();
?>
// place html or other php code below this.
If any users who have not registered and accesses this page1.php, they will be redirected to login page.
8. Display MyAccount menu to all logged in users
You want to show the myaccount menu to all those logged in users with links to change password, logout, settings etc... To show the menu place this code anywhere in your page1.php.
Only logged in users will see this menu.
<?
if (isset($_SESSION['user_id'])) {?>
<div class="myaccount">
<p><strong>My Account</strong></p>
<a href="myaccount.php">My Account</a><br>
<a href="mysettings.php">Settings</a><br>
<a href="logout.php">Logout </a>
<p>You can add more links here for users</p></div>
<? } ?>
You can add more links you want like submit etc..
Take a look at myaccount.php and see how this menu shows up
on the left side.
9. Access Admin area
Just login as administrator with username admin and password
admin123 and you will see Admin CP link below your myaccount.
You MUST change the password for admin once logged in
More information can be found in the FAQs section.