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. When viewing index.php on localhost I get
    Parse error: syntax error, unexpected ‘}’ in C:\xampp\htdocs\folder\login\register\index.php on line 100

    lines 99-102 of register/index.php are:

    I tried deleting/commenting out the bracket but that did not work…

  2. sorry your system won’t show the code with the php brackets.

    line 100-101 of the register/index.php is:

    }
    unset($objCore);

    I tried reversing the bracket and adding a closing bracket but got an error message on the registration page about already being registered even when I dropped and re-created the user table…

  3. Chad

    Thanks for your immediate response. I added “php” to the <? on line 20 and that fixed it.

  4. This script looks nice. I have downloaded it and will try it shortly. Although, I may wait until the weekend is up to see if you publish an updated version.

    “…I will try to make some update this weekend.” – Chadking 07/10/2009 at 18:13

    I usually make one include file containing the db access info and any hash values, random seeds, etc. This file I store off-site – i.e. out of the public HTML access area.

    Thank you for this nice piece of work.

    Greg

  5. Great script but I’m having a few problems – I found that with the resetpasswordhash field set to not null the site wouldn’t work but have now got to the point where I can get the confirmation email but if I click on the link it reboots my apache service (apache 2.2 running on win XP) but without leaving any error messages.

  6. 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.

  7. 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!

  8. 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!

  9. 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 .. ?

  10. 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

  11. 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

  12. 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

  13. 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

  14. 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

  15. 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?

  16. 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

  17. 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

  18. 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

  19. 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

  20. 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!

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

    M

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

  23. It doesn’t seem that I can post the code here, can you read what I posted earlier Chadking?

    Martin

  24. hi chad
    i keep running into the same 2 errors no matter how i structure the folders (as they were in the .zip or w/ everything inside public_html.

    public_index.php gives me:
    Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /homepages/34/d300058515/htdocs/login11/public_index.php on line 22

    index.php (inside register folder or outside):
    Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /homepages/34/d300058515/htdocs/login11/register/index.php on line 24

    line 22 of public_index.php and line 24 of index.php are exactly the same:
    if($objCore->getSessionInfo()->isLoggedIn()){

    if i try to access the “login11” folder, btw (which is what i name the overall login; i think you called it loginsystem2 or something) it gives me a stylized error 403 message so i guess that’s a good sign? i did re-name it correctly in “constants.php” (?) your help would be much appreciated.
    thanks,
    rob

    • Hi,
      and if you type “homepages/34/d300058515/htdocs/login11/public_html/”
      does it give the same error?
      You should not access public_index.php directly, the index.php inside of public_html does that! What you can do is remove the public_html folder, and rename public_index.php to index.php, but then you will need to check and replace in every file the references to public_html.
      greetings

  25. when i just type “…/login11/public_html/ ” i get this error message:

    “Fatal error: main() [function.require]: Failed opening required ‘../public_index.php’ (include_path=’.:/usr/lib/php’) in /homepages/34/d300058515/htdocs/login11/public_html/index.php on line 2”
    (this is the small “index.php” that was originally inside the public_html folder when i downloaded it)

    public_index.php and index.php are both currently inside the folder public_html. so if i renamed “public_index.php” to “index.php” i would have to move one 🙁
    ————–
    as an experiment, i moved index.php (the small file) into the login11 folder, and renamed public_index.php to index.php ….i get the same error messages for them in the new locations, whether i type their names directly or just the names of the folders that access them, except the error message for “index.php” references line 22 instead of 24, b/c it’s that same line of code that triggers the error 🙁 i’m a newbie. sorry.

    • rob, I am sure that’s some configuration issue in your php.ini file. I tried searching something about that and some seem to point to the “safe mode” property. I am not sure though…

  26. I am trying to run admin.php and am getting
    Fatal error: Call to undefined function mysqli_connect() in /home/www/*******/php/dbcontroller.php on line 15

    I am guessing that this is because mysqli is not enabled.
    The server is running
    php version 5.2.8
    mysql version 4.1.20

    Is there any way around this?

    Thanks

    Paul

  27. I think you need to enable the mysqli extention somewhere in php.ini, although I think it should be already by default for that vesion of php…

  28. I have now checked and mysqli is not enabled on my shared server.
    Is there any way around this – by using mysql for instance.
    No experience really in this subject so hoping for some advice.

    Thanks

    Paul

  29. Have been looking for something like this for quite some time, but nothing as simple and straightforward. Unfortunately I do not really know much about PHP, but do plan to learn. However, I need to install this on my website and there are a couple of things I need to know which do not seem to be indicated anywhere on here: 1. How do I access the admin area? After install everything worked fine, but when going to the admin.php page it redirected to the registration page and when registering it simply creates an account, but does not give me admin access. 2. Is there a way to have this automatically load the main website once the user has logged in, as opposed to merely showing the “logged in” screen? 3. How do I implement this for only one page on my site as opposed to the entire website? Thank you for your patience, and hopefully kind answers for a php newbie.

    • JohnDD,
      1- In order to be admin and be able to access the admin panel you need to set it directly in the database (usr_is_admin = 1). Once you do this, you can set as many users you want in the admin panel to be also admin.
      2- The “logged in” screen is just an example of what can be shown to the user after the login. You can show whatever you want as far as you make the logged in validation (like it’s done for that screen and for the admin.php). You can also redirect the user to the page you want:

      if (logged in)
      Location(your page)
      else
      show login form

      In your page:
      //again you need to check if the user is logged in
      if (logged in)
      show content
      else
      Location(/public_html/)

      greetings

  30. I am trialing on a different server now that supports mysqli
    When i access the register form id do not get a drop-down when i go to type the country.
    Any thoughts please?

    Paul

  31. THX THE SCRIPT IS GREAT! BUT WE NEED TO KNOW HOW ADD “EDIT USER FROM ADMIN” OR HOW ADD MORE INPUT LIKE AGE…

  32. so far am improving from my problem; but i still a lil more problem,:
    i have this error whenever i click on the user confirmation link from my mail.

    the requested URL /loginsystem/loginsystem/loginsystem/php/confirm.php was not found on this server

    what could be wrong here or with the url av checked am seeing the path is just ok.

  33. Hey dude theres a problem. I done it in dreamweaver and when I run it it IE browser and when I click the register button, theres an error here:

    Warning: require_once(sessioninfo.php) [function.require-once]: failed to open stream: No such file or directory in C:\AppServ\www\joemar\local\loginsystem\register\core.php on line 2

    Fatal error: require_once() [function.require]: Failed opening required ‘sessioninfo.php’ (include_path=’.;C:\php5\pear’) in C:\AppServ\www\joemar\local\loginsystem\register\core.php on line 2

    -What should I do PLEASE HELP ME ANYONE??

  34. hi, nice scrip, you do a very good job. i have a question. i would like to add one more filed like country, but i do not succeed. the field I’ve named device(a create a new table Device with 2 columns, device_code and device_name; in table users i insert a new row, device_code). can you tell me where i should make some change to have this filed working like country?

  35. Greetings ChadKing.

    On behalf of the community – much love goes out to you …
    This Login script looks like it could be really ‘Wow’.
    I say that becoz I have not managed to get it to work.

    i’m no programmer … so its hard for me to be specific here but the script takes my details via register form etc.
    I have created a new dbase and dropped the .sql file into it ok too.
    I noticed some files actually had dead links – straight up.

    Is there more documentation. on the script – Im afraid I need spoon feeding.

    ChadKing give thx in adv.

    DaLegsMan

  36. I am getting this” You don’t have permission to access /loginsystem1/admin.php on this server.”
    Is anybody knows what i should change in httpd.conf to get a permissin?
    Please help!!