PHP Login System Reloaded v1.1

Here’s an updated version of the PHP Login System. You can check the old version here. The following was added: 1. Registration fields: email confirmation password confirmation country recaptcha Email […]


PHP Login System

Here’s an updated version of the PHP Login System. You can check the old version here.

The following was added:

1. Registration fields:

  • email confirmation
  • password confirmation
  • country
  • recaptcha

Email confirmation and password confirmation are configurable fields. By default they are shown, but if you wish to remove one or both of them you have to set it in the file constants.php:

define("REPEAT_EMAIL",true);
define("REPEAT_PASSWORD",true);

2. Table fields:

  • the user ip,
  • number of logins of a user,
  • flag is_admin
  • flag is_blocked
  • new table – Country table

3. dbcontroller class sanitizes user input data

4. Edit Account Area

5. Admin Area – incomplete (for next version)

For now just the list of users is shown and a world map indicating where the users come from.  You can delete Users and set them as Admins. If there are no users to list, no map is shown. Also the User seeing the panel is not shown.
Note that in the demo you will not be able to see the admin part – for admin reasons 🙂

6. New CSS

7. Some other small details in the php code.

For the next version I am planning to :

  • add all admin functions
  • improve and improve ….

To use the recaptcha you need to get a public/private key here . Then you need to define them in constants.php:

define("PUBLICKEY","XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
define("PRIVATEKEY","XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");

In order to use the demo for those who have registered in the previous version’s demo, you need to register again (in the demo login system), since I had to set up another database for it.

Hope you like it. Any suggestions or improvements are welcome!

DEMO

Download the source code here

Tiny break: 📬 Want to stay up to date with frontend and trends in web design? Subscribe and get our Collective newsletter twice a tweek.

chadking

Chadking is an absolute geek that rarely leaves the comfort of his 3-screen desk. He is a self taught programmer and is addicted to all possible legal drugs.

Stay in the loop: Get your dose of frontend twice a week

Fresh news, inspo, code demos, and UI animations—zero fluff, all quality. Make your Mondays and Thursdays creative!

Feedback 287

Comments are closed.
  1. The code is really nice and thanks for sharing. I have a little problem with redirection to another page after I am logged in”if($objCore->getSessionInfo()->isLoggedIn())” . Does anyone know how to do it?

  2. Great login and registration system with clean and nice code.
    I’ve tested it in local server and its worked !
    Thanks Chad..

  3. Is there a way to configure the system to send out emails from a local host? I have tried to go through the registration on my local machine and send myself a confirmation email but have not been successful.

  4. Great secure login system!

    Should there be an option to resend the initial registration confirmation email incase it is deleted accidentally ?

    Whilst testing the script I managed block myself out by deleting the email confirmation.

    I can reset my password any number of times but I cannot login because I do not have the registration confirmation email and I cannot re-register because my email has already been registered.

  5. Can anyone tell me how can I add a new user so that I could test the system on my localhost? Is it enough to add manually a record to the database? However, it doesn’t seem to work.
    I will be grateful for any resonse!

  6. I have the system up and running but the confirm.php is not showing up after I click on the emailed link. I am getting a 404 page.
    I have tried changing around the ../ to ./ but no change.

    Also the hash is in the url and it should not be there. I have been trying to work out how to take that out.
    any help would be great.

  7. Your system is very good but i just want some pages to protect or you can say just few pages which are necessary for site admin for managing site crucial data and statistics.
    Which just need ONE id and pass or Few mod id and pass too.. can we accomplish this with this script if yes than how ?

  8. Hey Chadking
    Great script and a big improvement on jpmasters version.
    It works perfectly on my home windows php installation but when I upload it to my live linux server the registration page just hangs. I have checked sendmail with a testscript and this works fine so I am now stuck at this point, any ideas please?
    Note that the windows installation uses smtp if that gives any clues?
    Thanks
    Mike

  9. Registration hangs
    I believe I have the answer to the registration page problem, the error is from the recaptcha site, the solution is as follows:
    1) download the latest recaptcha files from their website and replace the old ones in this script
    2) edit the recaptcha.php pages and wherever you find an entry for ‘www.google.com’ replace this with the ip address of google

    Worked perfectly for me after this change so it must be some sort of dns error in the recaptcha system that holds up the whole registration process.

  10. Hey cool. I just uploaded and rigged the system. Been an interesting week.

    1. After upload, change the folders from 775 to 755. (Is that safe?) Fixes a number of install problems mentioned above.
    2. In public_index.php, add one level of directory and that seems to fix all the ../ problems mentioned above:
    <?php
    require_once("../(directory level)/php/core.php"); because this is the first time and after that all other references will be fine (you don't have to change ../ to ./) Am I making sense? I use a subdomain and a pointer.
    3. I changed the table from users to (my name)_users because I already had a users table for another application and didn't want to mess it up. Just copy and paste into a text editor and then search and replace all instances in the dbcontroller.php file. I think I counted 22 instances??
    4. I'm thinking I'll change the Country table to a table listing names of schools. My application is for teachers from a large number of schools and the country doesn't matter. Pretty easy to do. The table can still be called Country in my db but the list and the label could be quickly changed so users won't know the difference.
    5. I have one problem with email registration and password reset:
    click here (my domain).com/resetpassword.php?c=(numbers)&email=(myaccountname)%40hotmail.com
    There's a %40 where the @ should be when I look at the emails. I can fix it by hand and then they will work, but my users won't be up for that. Not sure why they are being decoded this way??
    6. I had to change all the 'public_html/index.php' to 'public_index.php' to get all the back links to work.
    7. I get one error on the admin page:
    Warning: mysqli_free_result() expects parameter 1 to be mysqli_result, boolean given in /(lots of stuff)/php/dbcontroller.php on line 433
    Any clue about that?
    8. If you added a simple text form, you'd have a pretty secure user email system going on.

    Thanks. Keep on rockin.

  11. Hi,

    Great script, you really made a lot of changes to the original script.

    I have ran into a problem, I added new fields did the whole process of adding it to the processregister_x and _register functions as well as the dbregister function also added the fields into the database.

    When I test the new fields and click on register the loading image just keeps loading and goes nowhere, but it still sends out the email and creates a new database row.

    Anything I could be doing wrong?

    Thanks.

  12. Hello~

    Could anyone here kindly help to advise who went wrong with script message as follows.

    It’s new installation with db configuration only, wondering if any configuration is missing?!

    Appreciate any advice.

    Warning: mysqli_connect(): (28000/1045): Access denied for user ‘abc’@’111.111.111.111’ (using password: YES) in /abc111/php/dbcontroller.php on line 15 Warning: mysqli_close() expects parameter 1 to be mysqli, boolean given in /abc111/php/dbcontroller.php on line 455

  13. just found my mistake for the db access configuration. the demo login page is displayed now.

  14. im trying to use another recaptcha for this great script. the registration can now display corresponding message for empty field and wrong recaptcha input respectively, as well as verifying the recaptcha input user keyin is correct.

    However, when the recaptcha input is correct, the previous error message, e.g. empty or wrong input, is still displayed while registration can still be successful.

    Any way to not display the previous error message when the recaptcha input is correct?!

    Any advice is appreciated.

  15. the issue is finally resolved… : )

    it’s related to the html class and id not being specified, so that when mouse cursor was in the input text field, the previous error message was not gone.

  16. Just downloaded PHP Login System. I have a problem with register/index.php I get an error at line 100 indicating “E_PARSE syntax error, unexpected”}
    at index.php line 100″ Using PhpED as development tool. Tried to find unbalanced “{}” in index.php but find none. Also checked /php/core.php thinking it may be there but no luck. Any ideas?

  17. Anyone seen a problem in /register/index.php regarding line 100 and a ‘unexpected “}”‘? I am using PhpEd to run through and understand the code. Code seems to run until I get to the login screen and select “register”.
    The code looks correct and I looked for places where an extra “}” may be, found none
    getSessionInfo()->isLoggedIn()) {
    echo “Registered”;
    echo “We’re sorry $session->username, but you’ve already registered. ”
    .”Main.”;
    }
    else {
    ?>

    Registration

    Personal Details
    First and Last name

    Country

    For inserting a country, just start typing and wait a little. A drop down is going to be shown and you can pick your country.

    Account Details
    E-Mail

    Repeat E-Mail

    Password

    Repeat password

    Verification

    var RecaptchaOptions = {
    theme: ‘clean’,
    lang: ‘en’
    };

    Register

  18. Hi chad!
    great script!

    I have a question, how can I add additional field such as birthdate, contact etc.. I tried to add those fields but when I start to modify your script, everything doesn’t work.. can anyone help me, what should I do or where can I add additional fields?

    thanks..

  19. could anyone here kindly help to advise how to update a field in TABLE users? i’d tried to add in core.php following

    $this->dbcontroller->updateUserField($this->sessioninfo->getUserKey(), “my_field_name”, “my_data”)

    $this->dbcontroller->query(“my_query_here”);

    and even add a public function in dbcontroller.php to call it from core.php

    the executions work OK, but NONE of them really update the field in TABLE users.

    Any advice is highly appreciate.

  20. Hi, is it possible to change the content of each users page so I can add things to a diffenernt users page than everyone elses.

    Thanks for the script 😛

  21. MY captcha is not working?? Its saying: input error: K: format of the site key is not valid

  22. Hi ChadKing,
    Firstly, thankyou for the code, save me a lot of time, very much appreciated.
    Can you please relink the public and private keys I am trying to download them but I get an ERROR 404, or maybe explain to me how I would go about generating my own.
    Great! Work!
    toadz…

  23. Hi I am facing this error: What is meant:
    Input error: k: Format of site key was invalid.

    How i can solve to it

  24. hello how are you i need some help. im trying to create two different register pages, “one for customers and one for resellers”, and i have created the tables in my database:

    “users”
    “resellers”
    “active_users”
    “active_guests”
    “banned_users”
    now im trying to have the info for when customers sign up for the approicate pages and have the info go to the right pages. code below:

    function addNewUser($username, $password, $email, $firstname, $lastname, $address, $addressline2, $city, $state, $zip, $phone, $fax, $addresstype, $companyname, $businessphone, $resellpermitnumber, $issuedstate, $monthly){
    $time = time();
    /* If admin sign up, give admin user level */
    if(strcasecmp($username, ADMIN_NAME) == 0){
    $ulevel = ADMIN_LEVEL;
    }else{
    $ulevel = USER_LEVEL;
    }
    $z = “INSERT INTO “.TBL_USERS.” VALUES (‘$username’, ‘$password’, ‘0’, $ulevel, ‘$email’, $time, ‘$firstname’, ‘$lastname’, ‘$address’, ‘$addressline2’, ‘$city’, ‘$state’, ‘$zip’, ‘$phone’, ‘$fax’, ‘$addresstype’, ‘$businessphone’)”;
    mysql_query($z, $this->connection);

    $q = “INSERT INTO “.TBL_RESELLERS.” VALUES (‘$username’, ‘$password’, ‘0’, $ulevel, ‘$email’, $time, ‘$firstname’, ‘$lastname’, ‘$address’, ‘$addressline2’, ‘$city’, ‘$state’, ‘$zip’, ‘$phone’, ‘$fax’, ‘$addresstype’, ‘companyname’, ‘$businessphone’, ‘$resellpermitnumber’, ‘$issuedstate’, ‘$monthly’)”;
    return mysql_query($q, $this->connection);
    }

    but when i test it out. its not working. its repeating in info from one register page and puts into both, while the other page comes up as errors. how can i have these two pages inerts the proper info into the two different page without errors ?

    thank you
    sketchone

  25. Has anyone tried to use PostgreSQL with these scripts instead of MYSQL.
    The MYSQL version runs alright but when I am try to convert to PostgreSQL nothing seems to work and its just a blank page!

  26. hey chadking, i no this was posted like 4 years ago but if you still look at it I need, some help, for some reason every time I try and type a country for a registration form nothing shows up and on the bottom of the browser it says error on page, please someone get back to me as soon as possible cause i kind of want to get this project done. thanks for you time

  27. I am implementing this system in POSTGRESQL, finally it seems to work but there looks some problem in the javascript portion as the register, edit profile and send password button doesnt work. Has anyone done something similar?

  28. Got an issue where I get an “an error occurred bla bla bla” popup whenever I try and register. I think it is the javascript throwing the error. Any ideas?

  29. how would I go about deleting all the email aspects of the login form.. my hosting service doesnt allow emailing so that why I want to know how to disable it.. just like the email confirm thing and the forgot password email thing. plz help.

    hosting service: http://www.zymic.com

  30. Thanks for this great script. I am about to implement it on a site and was wondering if there is a newer version than 1.1?

  31. Hi Chadking,

    First of all …………….. great piece of work !

    I installed everything on a testsite, http://www.familiekant.nl/admin/ and it seems to work.

    When I fill in everything when I try to register, the error message pops up till I set everything allright.

    When I click on Register I see the Ajaxload image for a few seconds and than ………….. nothing 😉

    No error message, no record in the database, no nothing.

    Any idea what goed wrong?

    Kind regards,

    Arie

  32. everyone is complaining that the php wont confirm their emails. can someone help, i’m a newbie …… please and thanks in advance

  33. Hi All!
    I am a novice in PHP.
    What should I do after logging in, the user arrive at my Main Page? If I modify the index.php,It seems on the login page also.
    Thanks!

  34. I am getting this Error when i run it in browser: {PHP Warning: session_start() [function.session-start]: open(./sessions\sess_nr1qi6k50l2fdrj0981gbvpkf2, O_RDWR) failed: No such file or directory (2) in D:\Domains\jmedsci.com\wwwroot\loginjqry\php\core.php on line 22 PHP Warning: Unknown: open(./sessions\sess_nr1qi6k50l2fdrj0981gbvpkf2, O_RDWR) failed: No such file or directory (2) in Unknown on line 0 PHP Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (./sessions) in Unknown on line 0}

    Despite the fact that i gave it a location to save session….and i make the change in core.php file:
    public function __construct(){

    session_save_path(“./sessions”);
    session_start();

    }

  35. Really cool tutorial ! I have question what do you mean by

    “The only table that you have to create in your MySQL database is the following:”

    Please help answer back , I just started learning web development.

  36. A quick change that you might want to make is encoding the email for the password reset as rawurlencode, rather than urlencode, to avoid destroying + signs in email addresses (a perfectly valid character).

    Both changes would be made in the core.php file. In the functions confirmResetPasswordData() and processForgotPassword().