Ok. There aren't really any "members", as I wrote before, but a single login for Admin options (for me), so that data can be changed, no matter if I'm at home by my computer or not.
For the login I use a class "Admin", which has some functions:
validateLogin($uname, $pword) - Compares entered username and password to stored values in config file. Returns true/false
login($uname, $pword) - validates the username and password and logs in.
After the info has been succesfully validated (with method above) I store a session as so
PHP Code:
$_SESSION['Admin'] = array(
'uname' => $uname,
'pword' => $pword
);
loggedIn() - Checks weather or not I'm logged in and returns true/false.
This function is used every time I need to know if I'm logged in. For example if admin should se an extra link which others don't, or to see if I'm allowed to visit a page etc. It checks this like so
PHP Code:
return isset($_SESSION['Admin']['uname']) &&
isset($_SESSION['Admin']['pword']) &&
Admin::validateLogin(
$_SESSION['Admin']['uname'],
$_SESSION['Admin']['pword']
);
Oh, and by the way. These functions are all static, if it makes any difference, so I would call them like
PHP Code:
if (Admin::loggedIn()) {
// do things...
}
As I said, I'm new to AJAX. I use a library called 'Scriptacolous'. With it I've made a small script for editing text for images. I use all the build in functions in Scriptacolous to make a request to 'editImageText.php' with ID and new value as parameters. In editImageText.php I tried this:
PHP Code:
require 'path/to/classes/Admin.class.php';
if (!Admin::loggedIn()) {
exit('Error message');
} else {
// continue...
}
which always runs the exit command and returns the error message to the AJAX script.
Hope somebody can figure this out :P