PHP Login Script

A simple home made PHP/MySQL login script to protect your web page content from spam and bot registrations.

Features

I am releasing it free of charge.This script can be used for any personal or commercial purposes. I coded this script in my spare time and now i am sharing it with the community.

How it works

- User gives email and password and the script searches for that email and password in the database and if found it redirects to myaccount.php

- The password is stored in md5 format. When the user enters his password, the script converts the password to md5 string and then compares this to the md5 of the password stored in the database. We never want to know or store the real password of users. That is why we are using md5.

- This script once logged in registers 1 session variable $_SESSION['user'] and which is available on all pages. Make sure that you put session_start() on top on all the pages where you want to login protect.

- While Registration, the script checks for already existing email before proceeding to create an account.

Demo

Download (zip 27k)

Requirements

- MySQL 3.x or later
- PHP 4+ with GD Library
- Apache Server
- Linux

How to Install

1. First create a mysql database (say phplogin) for a particular user name (say guest) and password ( say guest). Then give all previleges of database to the user.
2. Copy the following SQL to create a table and structure

CREATE TABLE `users` (
`id` int(20) NOT NULL auto_increment,
`full_name` varchar(200) collate latin1_general_ci NOT NULL default '',
`user_name` varchar(200) collate latin1_general_ci NOT NULL default '',
`user_pwd` varchar(200) collate latin1_general_ci NOT NULL default '',
`user_email` varchar(200) collate latin1_general_ci NOT NULL default '',
`activation_code` int(10) NOT NULL default '0',
`joined` date NOT NULL default '0000-00-00',
`country` varchar(100) collate latin1_general_ci NOT NULL default '',
`user_activated` int(1) NOT NULL default '0',
PRIMARY KEY (`id`)
)

3. Open dbc.php to edit mysql database name, user name and password.

FAQs

1.How to protect pages with login script

All you have to do is just put the following code on top of pages you want to protect (only available to logged users) like myaccount.php, page1.php, page2.php etc... It should be on very top of every php page


<?php
session_start();

if (!isset($_SESSION['user']))
{
header("Location: login.php");
}
?>

<< other html or php content goes here>>

2. How do i show Members Top Menu

If you want to show members menu like my account | settings | logout, you may want to add the following code in every page you protect, so that the menu shows up for logged members. This options will only show up for members you have logged in.

<?php if (isset($_SESSION['user'])) { ?>
<p>Logged as <?php echo $_SESSION['user']; ?> | <a href="settings.php">Settings</a>
| <a href="logout.php">Logout</a> </p>
<?php } ?>

3. How do i change captcha background?

Just open the pngimg.php file and there you can change the background for the captcha. I have made 4 background images of different colors with this.

imageCreateFromPNG("bg1.PNG")

 

 

You can also discuss this script in the forum regarding this script. However, I wont be able to provide assistance or support for this script because of my busy schedule.

Copyright (c) 2008 PHP-Login-Script.com . All Rights Reserved | Privacy