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 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 […]

From our sponsor: Guide customers along the path to purchase with our award-winning platform. Starting at $14.99/mo.


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.

http://tympanus.net/codrops/author/chadking/

Stay up to date with the latest web design and development news and relevant updates from Codrops.

CSS Reference

Learn about all important CSS properties from the basics with our extensive and easy-to-read CSS Reference.

It doesn't matter if you are a beginner or intermediate, start learning CSS now.

Feedback 287

Comments are closed.
  1. I successfully altered some of the files to work with my server (some of the provided code wouldn’t work for some reason). It’s all working now.

    I love the map feature. I plan on changing the country table in the database to states and I plan on solely using states instead of countries (I expect most of my users to be in the states rather than out of country). Where exactly can I change the map to that of just the U.S. and states?

    Basically I’m trying to make the admin part more localized instead of a broad country scope.

  2. Hi Chad,

    Thanks for what looks to be a very good script and one which I’ll be able to implement with some current sites!

    I tried running the script on one clients server and it appears the server does not support the MySQL Improved extension (something I’ve not used or run into yet – completely unfamiliar). Is it possible to easily convert the code to use regular PHP MySQL commands? I will look into the MySQLi functions substitution but only if you think it’s simple enough to do.

    Thanks for the product and your time!

  3. Hi Chad,

    First I would like to thank you for the great code you share. I am very grateful and I’m sure I’m not the only one!

    I have been playing with this great login system, and I noticed the following:

    If a user forgets his password and wants to request a new one, he will receive an email with a link (containing the hash key) to reset the password.
    He then clicks on the link, and is able to reset his password, which is great!

    But the url (which contains the hash key) can be accessed at a later time, allowing an unexpected user to change the password…

    Would it be possible to change the code so that this cannot happen?

    Thank you and best regards!

  4. Hi
    -Is it possible to connect this login system to a a phbb forum?
    so if they log into a website they can go to the forum and they will be logged on .. ?

  5. I am trying this, but i cant get it to show up as a page. It always trys to download the file, and when i do, I cannot view the page on internet anyways? What is up with this? How do I get a php page to show up as php? ANd how do I combine this into my site? I need a tutorial T.T U can e-mail 1 to me at shaina_hurst@live.com

  6. I’ve now found out that if I manually set usr_is_admin to 1 in tables.sql, when I log in it gives me an admin link. The only trouble is I have set up 2 or 3 users using different email accounts and they can all access the admin stats? How can you make it so that only I can access the admin stats and not everybody?

    • Hi,
      to do so, you should either have that flag set to 0 by default and then set it to 1 for the user you want, or you leave it as it is now, you go to the admin panel and you set the users you want to be admin.
      greetings

  7. Hi Chadking,

    Right I’ve got it, I change the flag to 1 on my login in PhP MyAdmin, where do I store all the pages I want people to see when they have logged in, in the public_html folder?

    Thanks

    • Hi,
      you can store the pages anywhere. Just always check if the user is logged in before you display the content of the page!
      greetings

  8. OK, how do I check if the user is logged in, do I have to put some code at the top of the page?

    • Hi,
      In order to use this script you have to know at least a little bit of php. So, take your time, open and look at the files and try to understand them.
      I am glad to help, but at least look at the files first!
      greetings

  9. Hi,

    OK I’ll see if I can figure it out, I do know a bit about php.

    It really is a great script!

    Thanks

  10. Hi,

    If you amend the code on public_index.php to:

    getSessionInfo()->isLoggedIn()){
    echo “Logged In”;
    echo “Welcome “.$objCore->getSessionInfo()->getUserInfo(’email’).”, you are logged in. ”
    .”[Edit Account]   “;
    if($objCore->isAdmin())
    echo “[admin]   “;
    echo “[Logout]
    .”[Click here to continue]   “;
    }
    else{
    ?>

    it works but you can still access the page without logging in!

    Am I close??? 🙂

    Thanks

    • Martin,
      I ‘m not sure if I got you! How do you mean you can access the page without being logged in? Which page? Do you mean that you can type …/public_index.php without being logged in?

  11. Hi chad,

    i need help really help!
    i dont understand why my server settings is working well with JP system and not yours, especially the mailing part. i have my SMTP=localhost,
    mail_from=mail.zed.com. and rest on constants = mail.zed.com. i av even tried. setting it http://www.zed.com, still not working. please help. i av really lagged behind because of this. thank you.

    • Hi,
      If it works with the JP one it should work with this one since I didn’t change much concerning the mail function! I am not sure if I can help you with that, I didn’t configure it myself! I have it hosted in a server in which I didn’t need to configure that… Did one of you guys here had the same problem / solution that could help Gabriella solving this issue? Thanks
      greetings

  12. Hi chadking,

    I think I may have figured it so that logged in users see one element of the page and users who are not logged in and try to paste the url directly into their browser see a different message.

    On the public_index.php page I have added an extra line:

    .”[Click here to continue]   “;

    (see below)

    getSessionInfo()->isLoggedIn()){ echo "Logged In"; echo "Welcome <b>".$objCore->getSessionInfo()->getUserInfo('email')."</b>, you are logged in. " ."<a href="../editaccount.php" rel="nofollow">[Edit Account]</a>   "; if($objCore->isAdmin()) echo "<a href="../admin.php" rel="nofollow">[admin]</a>   "; echo "<a href="../php/corecontroller.php?logoutaction=1" rel="nofollow">[Logout]</a>" ."<a href="../page2.php" rel="nofollow">[Click here to continue]</a>   "; } else{ ?>

    Then on all future pages do I need to code the pages as below so logged visitors see the page wrapped in php and if you try to access the page without logging in you will only see:

    This is what you see when you are not logged in! (as per the code below

    initSessionInfo(); $objCore->initFormController(); ?> Page 2 getSessionInfo()->isLoggedIn()){ echo "Logged into page 2 using the php script from public_index.php"; echo "Welcome <b>".$objCore->getSessionInfo()->getUserInfo('email')."</b>, you are logged in. " ."<a href="../editaccount.php" rel="nofollow">[Edit Account]</a>   "; if($objCore->isAdmin()) echo "<a href="../admin.php" rel="nofollow">[admin]</a>   "; echo "<a href="../php/corecontroller.php?logoutaction=1" rel="nofollow">[Logout]</a>"; } else{ ?> This is what you see when you are not logged in!

    Is this the correct way to code the public_index.php and all pages once logged in?

    Thanks

    Martin

    • Hi,
      yes you need to do so!

      Basically you need to do something like:

      if (user is logged in){
      //show whatever html you want! You don’t need to do echos. If your html is //big I would actually close the php tag after the previous if statement and //include html code here
      }
      else{
      //user is not logged in
      //you could redirect him to the main page or to some login page for example
      header(“Location: login.php”)
      }

      greetings

  13. Hi chadking,

    I’ve tried both of the below but just keep getting page errors (I have removed the ? from the php open and closing tags for the purpose of pasting here:

    getSessionInfo()->isLoggedIn()){
    //show whatever html you want! You don’t need to do echos. If your html is //big I would actually close the php tag after the previous if statement and //include html code here
    Logged in content to go here
    }
    else{
    //user is not logged in
    //you could redirect him to the main page or to some login page for example
    header(“Location: login.php”)

    >

    and

    getSessionInfo()->isLoggedIn()){
    }
    ?>
    //show whatever html you want! You don’t need to do echos. If your html is //big I would actually close the php tag after the previous if statement and //include html code here
    Logged in content to go here

    Can you tell me what I am doing wrong please?

    Thanks

    Martin

  14. Hi,

    I’ve got it down to the below basic code but am not sure what to wrap “My html to go here” in because when I try to access the page I get the error:

    Parse error: syntax error, unexpected T_STRING in /home/thinksma/public_html/loginsystem1/page3.php on line 26

    Here is the code (without the? in the php tags)

    getSessionInfo()->isLoggedIn()){

    My html to go here

    }
    else{
    >

    This is what you see when you are not logged in!

    Martin

  15. OK here you go:

    initSessionInfo();
    $objCore->initFormController();

    ?>

    Page 3

    getSessionInfo()->isLoggedIn()){

    My copy to go here

    }
    else{
    ?>

    This is what you see when you are not logged in!

  16. Obviously this site strips out the php, would it help if I put at the beginning and end?

    M

  17. Hmm, I don’t know if you are receiving the code well enough but I cannot post it on here it seems!