Forum Moderators: coopster
$sql = 'SELECT id_user FROM user WHERE id_user='.q($this->id).' AND user = '.q($this->user,true).' AND code = '.q($this->code,true).' AND ip = '.sprintf('%u',ip2long($_SERVER['REMOTE_ADDR'])).' AND flg_access = 1';
The field id_user is the only INDEX field in the table.
Right now the service has around 400 users... and that works ok for that. But what will happen when i have 1 millon users when executing that sql statement?
Here is the full code:
function validation() {
global $cnn;
if(is_numeric($this->id) && $this->user && $this->code) {
$sql = 'SELECT id_user FROM user WHERE id_user='.q($this->id).' AND user = '.q($this->user,true).' AND code = '.q($this->code,true).' AND ip = '.sprintf('%u',ip2long($_SERVER['REMOTE_ADDR'])).' AND flg_access = 1';
$rs = &$cnn->Execute($sql);
if($rs->EOF) {
header('Location: '.URL.'logout?msg=105');
die();
} else {
# Session valid
return true;
}
} else {
header('Location: '.URL.'logout');
die();
}
}
And if you aren't, you may still have an issue with that method -- what if you suspend a user's account and that user is in the middle of a session? Without hitting the database again, you have just lost control over that session and the suspended user keeps on navigating the protected area.
As far as performance goes, the database interaction is going to be extremely fast. With a session you are still opening a file, it's just at the filesystem level as opposed to the database level (unless of course you are using the database to manage sessions as mentioned earlier).
Just some considerations ....
MySQL AB On-Demand Web Seminars [mysql.com]
Specifically, Session Management with MySQL [mysql.com]
If it is not equal, then we know there's a problem. (perhaps the user was deleted, or code was set to NULL becasuse someone accessed with the same username from another machine).