<?php
session_start(); // start session cookies
require("Login.class.php"); // pull in file
$login = new Login; // create object login
$login->authorize(); // make user login
?><?php
// username to login into page
define('LOGIN_USER', "admin");
// password to login into page
define('LOGIN_PASS', "secret");
?>
Comments
Add more users?
Hello!
I have a question:
- Is there any way to get more than just one user?
Answer
This is a very simple login script that only supports one user. If you need a system that allows multiple users, you'll need to search for something more advanced that stores the users in a database.
Blank page
I uploaded the existing Login.class.php page, along with my secure page (with the index.php code placed at the very top) to my server. When I call up the Login.class.php page, it's blank. Any idea as to why?
Answer
You don't need to load Login.class.php in your browser (and it should be blank). What you load is the index.php file (or any other file you are protecting). On the index page, when it gets to $login->authorize(); that is the breakpoint and the index page will not load anything past that point unless the matches/checks in the Login.class.php file are met. If the login conditions are not met, you will get the prompt() code from the bottom of Login.class.php but the browser is still on the index page. Login.class.php is completely hidden to the user, it's simply there to contain all the necessary login code.
btw: your other comments were there, they just don't show for unregistered users until I approve them.
Blank page
Thank you. I graduated with a 4.0 in web design, but have been part-time freelancing ever since and as they say, if you don't use it, you lose it. I knew the problem was me, not your script. And thank you for keeping me from looking like a total idiot with the multiple posts! I swear I'm smarter than I appear. lol
Security Hole?
I love your classes and they are saving me a lot of time. However I notices what looks like a security hole today:
I have the logout link on page.php which points to: /page.php?action=clear_login
Now, after user has been logged out, if someone else comes and clicks the browser back button, they are back in the previous user's account.
I don't know if I'm not using this class as intended what.
[edit]
I commented in the wrong section, sorry; I'm actually using the BETA Login.singleton.php not Login.class.php
Answer
The user is completely logged out at that point. If they tried to change something or actually interact with the site it would not let them and it would send them to the login prompt.
However, you are correct in that any static information on any of the "back" pages would still be viewable. That's due to the browser caching those pages, not actually anything in the script. That's not a big concern for what I've used the script for so I've left it like that. However, I believe there is either some META tags you can use or even PHP header() tags you can use to prevent a page from being cached by the browser.
Neat!
Solid looking script! Sessions and remembering the user are crucial. Looks great.
I have integrated your V3 wrapper class script with phpuserclass.com and it seems to work really well. What I like about it is how it integrates with a MySQL database to check if a user is logged in. Perhaps you can expand on that code as well, allowing for an even tighter integration with your wrapper class?
Keep up the good work!
Answer
I went ahead and released a BETA version of my PHP User Login and Management for those interested in playing with it.
Like what I see
I'm just starting in php but have been coding in html for some years. I'm building a new php site and I'm trying to use it to learn php by implementing bits of scripts I find and modifying them. I like this script and will hack it out to my liking. I was getting an error while testing the script. The same error in line 240 thing. By fixing the command listed bellow to took care of it.
This command bellow was causing the error.
<?
}#-#foreach
?>
Changed to this:
<?php}#-#foreach
?>
This is a great script non the less.
Thank you for helping me to learn php
Answer
That's a PHP configuration setting the host can set. they can set "short_open_tag=off" and you have to use the full <?php and can not use just <?