PHP Login Script

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!

Home

Install Instructions

FAQs

Forum

Contact me

Advertise

FAQs - Frequently Asked Questions

Please carefully read install instructions before you read this page.

Is this script free?

yes, this script is absolutely free. Please feel free to use it anywhere be it personal or commercial use. Please do not remove "Powered by PHP Login Script v2.3" and the copyright messages in the script.

If you want to get this credit link removed, there is a small $5 removal fee (which i believe is worth the effort). If you have site where you will be using the script,

Please note: I do not provide support for this script for purchases as well. Use of the script is at your own risk.

 

Credit Link Removal (Standard License)
USD $5

 

Single site license for removal of "Powered by PHP Login Script" credit link in your site.  

 

Credit Link Removal (Unlimited License)
USD $50

 

Unlimited license for removal of "Powered by PHP Login Script" credit link in your site.  

 

Copyright Removal (Developer license)
USD $99

 

Developer License gives permission to remove copyright in source code and removal of "Powered by PHP Login Script" credit link in unlimited number of sites.

If you intend to sell the script, you have to buy this license.

 

Do you provide support for this script?

No, i wont be able any support for this script because of my busy schedule. I would be glad to offer assistance in this discussion forum.
It would also help if you have a reliable host.

How do i change the background of error messages by javascript?

Just open styles.css and change the code under .error class

How to i change the landing page after login?

By default the script redirects to myaccount.php upon successful login. You can change that to any php page you want as long as you have login protected it.

To do this...

Open login.php, look for header("Location: myaccount.php") and replace the myaccount.php to new landing page. It should be on the same folder as of php login script.

How do i install the login script in domain.com root?

Just unzip and copy all the files to public_html folder of the domain. Note that the script may not work properly if installed in subdomains. It will work if installed in a subfolder.

why i am not able to login?

If you are unable to login, then it could be either your account not activated or could be banned.

Why is captcha is not working?

you have to get public and private keys specific to your domain from http://recaptcha.net. Registration is free there. You also need to download php library file - recaptchalib.php and place it on the script folder.

How to 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.

<?
include 'dbc.php';
page_protect();
?>

If any users who have not registered and accesses this page1.php, they will be redirected to login page.

How to 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.

Note: For this to work, you have first protect with login page. (see above faq)

How do i make changes to font and color of textbox in login page?

Its easy! just open styles.css and look for this style .loginform #txtbox.

How do i change the email templates for this script?

If you want to change/alter the mail template, you will need to open certain php files and do the change like mail label, mail footer etcc. The files are

register.php
activate.php
forgot.php
admin/newuser.php

You will find the entire mail template with assigned to $message variable.

How do i add a new field to the registration form?

Here is how you do it...

Lets say you want create a new field ZIP code in the users profile.

1. Create a new field zip in users table in your mysql database. Use phpmyadmin for this.
2. Open register.php and above country, place this html code in the form

<input name="zip" type="text" id="zip" class="required" minlength="4">

This class="required" minlength="4" is added here because javascript forces the user to enter minimum 4 character for zip code.

Similarly you have change insert statement within the php code.

Go to line 61, look for `user_name` and near it type `zip` separated by comma. It should look like this.

`user_name`,`zip`

and similarly look for '$user_name' and near it

'$user_name','$_POST[zip]'

Make sure you filter the zip POST variable using mysql_real_escape_string() function as it is dangerous to insert into database without filtering the input. If need be create a variable $zip_code above line 61 and assign it to insert.

$zip_code = mysql_real_escape_string($_POST['zip']);
'$user_name','$zip_code'

4. Finally, in this step what if the user wants to update their ZIP code? They can login and change their address and zip in mysettings.php. Open mysettings.php and on the html form add this line.

<input name="zip" type="text" id="zip" value="<? echo $row_settings['zip']; ?>" class="required" minlength="4">

and in the php code of same page look for

`tel` = '$_POST[tel]',

and below it make a new line and write the code below..

`zip` = '$_POST[zip]',

Users can update their zip code and other fields after logging in.

Thats it!


Common Errors and Troubleshooting

"Cant select database"

Surely you must have given wrong database name. For example if you are using cpane, your database name like username_databasename

Warning: mysql_connect() [function.mysql-connect]: Access denied for user xxx (using password: NO) in /home....l/dbc.php on line 3

Are you sure you have created database user and password?? If you have created one make sure you have give FULL ACCESS RIGHTS for the user to the database. If you use cpanel, you can easily add user to database and in the next step you set ALL previlege.

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource - Table 'xxxx_phplogin.users' doesn't exist

Have you copied and pasted the SQL for creating users table? see install instructions

"Warning: session_start() .....Headers already sent..."

Make sure there is no html code on very top of page. Even blank space could cause this. The very first code your php page should have is

<?
include 'dbc.php';
page_protect();
?>

If you find php include statements, place it elsewhere other than top of page.

Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()

Are you running this script in your local computer either with WAMP or Xampp?? If so just ignore this warning because normally your local computer will not relay mail outside the network. Just upload the script to real server and it will work fine.

"Emails sent are landing on Spam folders"

There could be several reasons for this. .This script at present only uses mail() function to send notify emails. You cant do anything with that, unless you set your server to

1. Reverse IP for your mail server
2. Create SPF record
3. Set domain keys for your domain

ask your host about it.

You may also want to consider using SMTP mail to send notification emails. There are free open source smtp library for php like phpMailer which can be used with this script..

"Activation Link in email not working - 404 page not found"

As of php login script v2.0, the script automatically detects the path. If you still unable to resolve it, you will need to hardcode the path of activate.php inside the script. If you know the path, just type on the browser and see whether the activate.php is loading.

Just open register.php and look for this line.


http://$host$path/activate.php?user=$md5_id&activ_code=$activ_code

and hardcode the correct path

http://domain.com/folder/activate.php?user=$md5_id&activ_code=$activ_code

Notice: Undefined index: email in C:\WAMP\www\login.php on line 4

see this solution

More information can be found in the FAQs section.