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

Tagged with:

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 up to date with the latest web design and development news and relevant updates from Codrops.

Feedback 287

Comments are closed.
  1. I think you have to look at the permission of the file admin php. I dont think you need to touch httpd.conf!

  2. Hi i have a small problem. I tried to edit an account, but the change what i made are not save to db. There are no error message in this process. Any idea?

  3. Hi, I’m working for my group website, and I plan the login system is intergrated with Social Engine Script. But I don’t have any idea how to modified your script. Thats really complicating scripts. I even can’t run it on my localhost. can you help me?

  4. i’ve solved the problem with my localhost, so now, anybody could help me to integrate it with social engine? Here’s information that you might wanna know. table name = se_users . instead using username for username records, they use user_username and user_password variables.

  5. Greetings Chadkin,
    Well, i solved my problem and it was as always quite simple as it looks right now:)
    But i have another question: if i would like to add some more fields, for example, address and city, can you please point the document where i have to make changes. I was playing around with dbcontroller.php for a while and I changed DB table, but for some reason it just does not collect the data.
    Please, let me know.
    Thanks again for a great script.

  6. Elena,

    I understand your fustration! I tried doing this several times with another php script (a previous one by jpmaster77). What you need to do is when creating new fields, you need to put them in the same order in your MySQL database as you did them in your php code. Wang bam, you should set them up just fine!

    Dan

  7. Hi Elena,
    you need first of all to add those fields in the user table. You can do that by executing something like this
    “ALTER TABLE USER ADD city VARCHAR(30) NOT NULL;”
    in the mysql database. Then, if you wish that these fields are required in the registration, you need to change the index.php of the register folder, the dbcontroller.php, and the core.php. For all these changes just follow the flow of a registration process. For example in the dbcontroller you have the function that inserts data into the user table.You need to add these additional fields to that query. But I would suggest that you start by defining them in the html of the register/index.php.
    I hope it helps.
    Greetings

  8. Daniel, I am sorry but that is not true. The order does not matter. As far as your queries are well defined, the order of the fields in the table is irrelevant. Thanks anyway for your comment!
    Greetings

  9. Chadking,

    Sorry! Its just how I got to get a previous script working, having it all well organised, etc.

    How long is it before we can expect the release of version 1.2?!

    Dan

  10. Hi, you can expect already a new release, I can’t tell you when though, but I am open for any suggestions concerning a future version of this system.
    Greetings

  11. Hey Chad,
    Excellent work with the scripts, I’m learning PHP as I go and your code has been a great asset for my learning. However I am encountering some difficulty trying to make use of the tablesorter 2.0 jQuery plugin. On the page I’m testing with I’m including index.js – I’ve added the function from the plugin to initEventHandlers. I’m receiving no errors or output, firebug shows the script is loading properly but I’m not receiving any of the intended results.

    Do you have something else setup to protect changes or have you modified jQuery in any way?

    Thanks!

    On a side note i used your “handler” method – using Core.php to call upon functions I’ve dropped into another fd_dbcontroller function and its working great. I’ve done this for consistency but is there a performance gain to be had by hiding the members in this way?

  12. Never mind, the plugin is working fine. I just spend 90 minutes troubleshooting something that is working as intended.

  13. How can I tweak the script to redirect an specific user to an specific page instead of main.php? I’m guessing I will have to add a field in the db with the url, and then an if statement (if user = then this url) but I just don’t know enough php! Please help 🙂
    Kind regards

    • Luke, I think you can do that like you say. For that you need do add another field in the users table and change the code that checks if the user is logged in. The query that checks that should also retrieve that new field, and then you just change the line window.location = “url from db”.
      Of course you can always hardcode and say
      if user == user1
      window.location = anotherurl.php
      else
      window.location = main.php
      greetings

  14. Looks like this is just what I need for my site. I downloaded and installed the scripts and everything seemed to go ok. Got the keys for recaptcha. But when I try to register a new user, after submitting it seems to hang. just the three green flashing squares at the bottom of the page. Im sure i just missed something. Any thoughts??

    • Steve, try to see with firebug what’s being sent in the ajax response after you click register.

      greetings

  15. Steve,

    Does your host allow you to use mysqli extensions? I had that problem and decided to move host!

  16. Warning: require_once(../php/core.php) [function.require-once]: failed to open stream: No such file or directory in /hermes/bosweb/web068/b681/ipg.sorcher/loginsystem/public_index.php on line 2

    Fatal error: require_once() [function.require]: Failed opening required ‘../php/core.php’ (include_path=’.:/usr/local/lib/php-5.2.4/lib/php’) in /hermes/bosweb/web068/b681/ipg.sorcher/loginsystem/public_index.php on line 2

    Please help, i get this when i try go to http://dawnforged.com/loginsystem/public_index.php

  17. Parse error: syntax error, unexpected T_STRING in /hermes/bosweb/web068/b681/ipg.sorcher/loginsystem/php/constants.php on line 7

    There is no text line at constants.php. so i dunno how to solve this :/

  18. Hey Morten,

    What does your script say in public_index.php on line 2? That’s obviously the source of your problem.

  19. Hi Chad,

    I have noticed a little issue (Firefox and IE):
    If a user types his email in the form on the page password_forget.php and then presses the Enter (or Return) key instead of clicking “Send”, the page will refresh instead of validating the input with jQuery.

    Also I think it would be nice if the Enter key could be used to submit ANY OF THE FORMS (like register/index.php) in the login system.
    At the moment, this is not working with either Firefox or IE. With Google Chrome, the entire form is reset.
    This may not be working now because you have used a link (anchor) to submit the forms instead of an input type=”submit”.

    Could you please let me know how this can be fixed?

    Thank you and best regards,

  20. ?????? ??????
    Fatal error: Call to undefined function mb_internal_encoding() in T:\home\localhost\3\php\dbcontroller.php on line 13

    ??? ??? ? ???? ???????: “mb_internal_encoding(“UTF-8”);

  21. hi chad,

    Thanks a lot for this great script I’m working on my new website and want to integrate this login system on it i know nothing about php except some basics. can u please help me
    1. to put a link on top to display the status whether usr is logged in and if user is logged in then the logout link ( basically login and logout link) just a small link

    2. small login form as i want to put that on my main page so that any visitor can login by the time he enters the site or how can i adjust the current login form in 160px wide colum as when usr logs in messages of login stays at top with other links i want to make them log in on main page and keep them at their with logged in status at top

    like i made it with other script but its very confusing to alter http://www.manjeen.org/mhpages/home1.php

  22. Thanks for the script I’m working on it for a project of mine.

    Two things…

    First, there seems to be an awful lot of ../ when I think you mean ./ for example the public_index.php script has them in 10 places all of which seem to cause problems for the script. The other files seem to work okay.

    Second, is there anyway to do this without the Captcha? There isn’t really a requirement for it in my project as it’s only sitting on a local server so having a web based identification system doesn’t really work.

    I’m not sure where I need to look to prevent this from being activated.

    Thanks for your help.

  23. can somebody help me with this error..

    Warning: require_once(../php/core.php) [function.require-once]: failed to open stream: No such file or directory in /home/www/maszther.awardspace.us/index.php on line 2

    Fatal error: require_once() [function.require]: Failed opening required ‘../php/core.php’ (include_path=’.:/usr/local/php5/share/pear’) in /home/www/maszther.awardspace.us/index.php on line 2

    if somebody can help please send me a msg to mes.zter@hotmail.com

  24. That’s the problem I was having. Simply change the “../” to “./” and the problem will be fixed.

    ./ = current directory
    ../ = go back one directory

    The problem is that it’s trying to go back a directory instead of looking in the current directory where the file actually is.

  25. @Roberte: You can fix that “enter” bug by adding the following code into the initEventHandlers function at the top of the passwprocess.js file…

    if ($(‘#form_passwprocess’)) {
    $(“#form_passwprocess”).submit(function(e){
    PasswProcess.processPasswordSubmit();
    return false;
    });
    }

    Make sure that “return false;” line is in there though, otherwise it will try to use the standard submission processing.

  26. The register form layout is broken when using IE7, the capcha box and submit button are out of position

  27. Hello. When an admin logs in, no map is shown? How can you get the map to display?

    Thanks,
    Kate.

  28. Hi..

    This is great, however, I’ve hit a point which I don’t understand.

    When it gets to the dbregister function and attempts to run the insert

    $q = “insert into users(pk_user,email,flname,password,usr_confirm_hash,country_code,usr_ip) values(‘NULL’,’$email’,’$flname’,’$pass’,’$hash’,’$country_code’,’$ip’)”;

    I find the insert fails because the db field usr_resetpassword_hash is not allowed to be null be the insert.
    I’m still reading through the code but can’t see how this is supposed to work. Can anyone point me in the right direction..

    Thanks.

  29. Chadking,

    Like everyone else here, I love what you’ve done and also thank you for all the time that you have taken, and continue to take, to talk to everyone about it.

    I had messed around with the previous jpmaster’s script and really liked its “active user” feature–it will show what registered users have been active lately. Is any of that legacy code still left in the current version of this project? If so, how difficult would it be to reactivate that function? If not, any thoughts?

    Thanks for your time!

  30. Got an issue where I get an “an error occurred bla bla bla” popup whenever I try and register. Using an unmodified install, only change I did is add the <?php to register.php. I think it is the javascript throwing the error but I can't work out what is causing it. Any ideas?

  31. Hello!

    I’ve studied the code and could improve a lot, but I have a question …
    I only receive confirmation emails in hotmail, why?
    I have tested with gmail and yahoo and I do not receive a confirmation email = (

    • Hi Nicolas, maybe something concerning your mail server configuration? Are the emails landing in the spam at least?

  32. I only received the emails in the hotmail box, I tested on Yahoo and Gmail and do not appear in the inbox much less marked as spam = (

    The configuration file is correct, I have not changed …

    What could be the problem? The configuration of mail that gives me my hosting?

    Maybe you could be?

  33. I can’t seem to find any instructions for installation. Do you have any such instructions? Thanks.

  34. WOW! chadking, this is awesome. the site is just too good. alot of improvements in here. i av been away for long.
    this is great keep it up.

  35. hey there chadking.
    this is an awesome tutorial!
    Everything works perfect.. After i click the Register button the data inserts into my database and i receive an email with the hash in it.. My problem here is when i hit the register button it hides the button and shows the loading gif as it suppose to do.. but it stuck there and doesn’t shows the next page (Confirmed or Password Reset Successfully or Register successfully go to your email and confirm..).. don’t know why but i’m guessing that the jquery does not correspond with the data==1 and textStatus==”success”..
    thenx for your time!

    • Hey pol thanks,
      could you take a look at the response you get in firebug, when you click register?

  36. i’m not sure if i understood what you meant..
    but at the console tab.. under the POST http://site/…… i get this
    {“result”:-1,”errors”:[{“name”:”email”,”value”:”Email already in use”},{“name”:”pass”,”value”:””},{“name”:”flname”,”value”:””},{“name”:”country”,”value”:””},{“name”:”confemail”,”value”:””},{“name”:”confpass”,”value”:””}]}

    hope this will help you understood my problem..
    thenx!

    • Hey pol,
      it should just print {“result”:-1} when everything is OK. I see on your website that some more things are being printed (noscript …). You should take a look at your code and check if you don’t have any syntax errors and also all php tags are in the form <?php > If you want just send me the register/index.php to codrops@googlemail.com and I will take a look.
      Cheers

  37. hey chadking,
    i’ve manage to fix it!!:) The problem was the mail().. every time i’ve tried to register; jquery was waiting to send the mail.. but the mail never send so it just stand there and waits the mail to be send and; then move on.. i’ve tricked the php.ini on my wamp server (localhost) to send a fake mail and.. the script now works perfect!
    for those with the same problem here is how to trick localhost to send fake mails..
    http://www.php.net/manual/en/ref.mail.php

  38. chadking,
    This is a great and it has saved me a lot of time. I’m having one minor issue with the error messages. You clear out the error messages, i.e. invalid email, when the field gets focus. But this doesn’t work with an invalid captcha response. I was able to get around it by explicitely clearing the captcha error message when the register button is clicked but the behavior is different than the other fields. Is there a way to know when the captcha field has focus so the error message can be cleared?

  39. Hello chad,
    i have a problem which is no related to this topic, is it okay if i just post it here or is there a way i can contact you or send it to you if not here (its about my chat system am working on).

  40. hi this is a great script.. i have problems when i try to check

    http://iba-smlm.com/loginsystem2/public_index.php

    the error is:

    Fatal error: Call to undefined function mb_internal_encoding() in /home/ibasmlm/public_html/loginsystem2/php/dbcontroller.php on line 13

    is same error with all the other files

    how can i fix it ??? thanks for your help

  41. Fatal error: Call to undefined function mysqli_connect() in H:\inetpub\vhosts\unikdesigners.com\httpdocs\php\dbcontroller.php on line 15

    Getting this error can you help me….

    define(“DB_SERVER”,”localhost”);
    define(“DB_USER”,”login”);
    define(“DB_PASS”,”biotronics”);
    define(“DB_NAME”,”najmuddin_login”);

    This is the database setting