pajamas.php is the main pajamas program. This script gets the users authentication status from whatever module is currently loaded, probably 'pj'. Basically it's a container interface, enabling us to load plug-in authentication modules on-the-fly. They live in a folder called, unsurprisingly, "modules".pajamas.php.
include 'pajamas.php';
$auth = new pajamasSimple();
if ($auth->auth_user()) { /* do admin stuff */ } else { /* do public stuff */ }
include $_SERVER['document_root'].'/inc/pajamas.php';
var $_code_location = 'inc/js/sha256.js';
include 'pajamas.php';
$auth = new pajamasSimple('Myuid-plain');
.user.ini as it is sometimes); whose only session directive was session.use_trans_sid = 0 - though my root php.ini has the session path set correctly - this only needs to be specified once in the site's root php.ini, afaik; It solved the problem immediately.
include '/path/to/pajamas.php';
$auth = new authModule('uid');
$auth->_createForms = false;
$auth->_default_module = 'pj';
$auth->_code_location = 'js/sha256.js';
if (!$auth->auth_user()) {
echo $auth->getAuthCode(); // echo the pj javascript include
echo $auth->getLoginForm(); // echo a login form
}
if ($auth->auth_user()) {
echo $auth->getLogoutButton(); // maybe a logout button.
}
For the default sha256 module, install the PHP module as modules/sha256.php and place sha256.js in modules/client-side/. Serve the login page over HTTPS and load the script with echo $auth->getAuthCode(); in advanced mode. Set $auth->_code_location to the script URL for your installation.
$auth->_login_password = 'MyPassword';
(string) name of module file (minus .php extension)current choices are 'plain' or 'pj' (the best)
If, for some insane reason, you don't have access to a JavaScript- capable browser, use 'plain', otherwise, use 'pj'.
the plain module can be configured in exactly the same way as the pajamas module, and has many of its features, too; sessions, IP check, time-out, etc., the only difference being that the password is sent over the wire in plain text.
Though unlike HTTP basic authentication, which send the password with every single request, with the plain module, the password travels over the wires one time only.
var $_default_module = 'pj';
(string) default: 'password';a quick and dirty way to store your password..
or you could keep it in a database, or include from another file,. include '/some/other/place/config.php'; and set it externally..
$auth->_login_password = 'MyPassword';
Passwords are case-sensitive.
var $_login_password = 'password';
boolean (true/false) default: true;normally, we check the IP address of the authorising browser. However, if the user is behind a proxy farm (very unusual), this will break his session, as his IP will change with (possibly) each request. If you have users behind proxy farms, (or you are) set this to false, or else advise them to use *yet another* proxy (two proxies).
var $_check_ip = true;
boolean default: true;we can specify a time-out for the session. if you set this to false, the session is live until the client's browser is quit, or they log out.
var $_do_time_out = true;
(integer, minutes) default: 60;an hour is reasonable, anything goes. the demo uses 0.5 (30 seconds)!
var $_session_time = 60;
(integer) (max failed attempts) default: 10;they tried and tried, but it just isn't happening. Or else they are taking the p*ss. A script perhaps, some brute force. Whatever, it would probably be best for everyone if we halted them in their tracks after how many failed login attempts?
var $_big_luser = 10;
boolean (true/false) default: false;optionally we can prevent even correct logins from browsers that repeatedly sent bad logins..
If you set this to true, after($_big_luser) failed login attempts, the property $auth->_bad_user) will be set to true. Now, even a correct login will fail to authenticate.
You can check for bad users, and then do what you like with them..
if ($auth->_bad_user) { die('go away!');
If you leave kick_bad_users set to false, a correct login will override all previous bad logins.
The idea is, someone may be attempting to login from your terminal, and fail, so they receive a message informing them of the futility of it, *hopefully* they will stop now. If the *real* admin comes along, he should be able to log straight in, and shouldn't have the inconvenience of restarting the browser just because some twat was fooling around. But you can disable this behaviour by simply setting this to true.
var $_kick_bad_users = false;
boolean (true/false) default: true;pj generates some messages for the various error conditions, you can use these however
you like, and latest message is always in "_auth_message"
If you like, you can have pj display these messages just above the login form, so the user is aware that their password was incorrect, or whatever..
var $_do_messages = true;
boolean (true/false) default: true;If you are already inside a form, set this to false to avoid nesting forms, which will break html valiadation, among other things (including the md5)..
$auth->_createForms = false;
Remember you can also pass "true" to your form input function, to have a simple, div-less output, like this..
$auth->getLoginForm(true);
var $_createForms = true;
boolean (true/false) default: false; (validates, but is annoying)a good, mostly supported proprietary Internet Explorer property.
With this set to true, browsers will not annoy you to try and save the password (which, at least with the 'pj' module, is a one-shot useless mish-mash that will be useless the instant you logout, anyway).
Set this to true to add 'autocomplete="off"' to your password field. TADA! One of the rare occasions where Internet Explorer leads the way!
var $_no_autocomplete = false;
(string) default: '';Some modules may require included code.
In "pj", this sets the default location of javascript MD5 functions file and will be used to create the <script> tag that includes the JavaScript MD5 functions on your page, like this..
echo $auth->getAuthCode();
You can override the location by setting this..
$auth->_code_location = 'inc/sha256.js';
*before* you echo the code. relative or absolute paths are fine, just like a regular javascript include.
var $_code_location = '';
the main function, returns a boolean, true on authenticated, false if not.
returns an html string to load any external scripts (eg 'md5.js' <script> tag)returns the module's login form (pass true for a simple• version)returns the module's logout mechanism, usually a button. (ditto•)like PHP_SELF, the path of the calling script.boolean flag denoting browsers that sent too many bad logins.if using time-out, this returns the number of seconds remaining.spit out a string of any errors that may have occured. pajamas will catch session errors of type E_NOTICE, and store them, so you can use this to spit them out, if you really must.