Junior Spellweaver
- Joined
- Feb 6, 2013
- Messages
- 196
- Reaction score
- 25
CREATE TABLE `iplogins` ( `userid` int(11) NOT NULL, `ip` varchar(211) NOT NULL, `date` varchar(11) NOT NULL) ENGINE=InnoDB DEFAULT CHARSET=latin1;
mysql_query("INSERT INTO iplogins (`userid`, `ip`, `date`) VALUES ('".$_SESSION['user']['id']."', '".$_SERVER["HTTP_CF_CONNECTING_IP"]."', '" . date('d/M/y', time()) . "')") or die ("Error in query: ".mysql_error());
If only your create table query is any good...
Please, how hard is it to add the right datatypes????
mysql_query()
I was about to say the same thing.
And
Code:mysql_query()
$this->database->query("UPDATE users SET timestamp = ?, login_count = login_count + 1 WHERE id = ?",[date("Y-m-d H:i:s"),$this->user()->id]);
Awesome contribution
You asked for suggestions and mine would be to update the user's last online, rather than inserting data for when they were last online, I assume you have chat logs and timestamps for this kind of thing already?
PHP:$this->database->query("UPDATE users SET timestamp = ?, login_count = login_count + 1 WHERE id = ?",[date("Y-m-d H:i:s"),$this->user()->id]);
That's great, will update mine to that aswell.
function getIP()
{
/*
This function attempts to get real IP address.
*/
if (getenv('HTTP_CLIENT_IP'))
{
$ip = getenv('HTTP_CLIENT_IP');
}
elseif (getenv('HTTP_X_FORWARDED_FOR'))
{
$ip = getenv('HTTP_X_FORWARDED_FOR');
}
elseif (getenv('HTTP_X_FORWARDED'))
{
$ip = getenv('HTTP_X_FORWARDED');
}
elseif (getenv('HTTP_FORWARDED_FOR'))
{
$ip = getenv('HTTP_FORWARDED_FOR');
}
elseif (getenv('HTTP_FORWARDED'))
{
$ip = getenv('HTTP_FORWARDED');
}
else
{
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
}
function insertIPLogins($userid,$userip)
{
$database = Database::getInitialize();
$time = time();
$stmt = $database->query("INSERT INTO iplogins (iplogins_userid,iplogins_userip,iplogins_timestamp) VALUES (?,?,?)",[$userid,$userip,$time]);
$result = $stmt->results();
return $result;
}
CREATE TABLE `iplogins` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`iplogins_userid` int(11) NOT NULL,
`iplogins_timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`iplogins_userip` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1
Rather than saving every IP address for every login, you should compare the IP that's logging in with the one that is in the registered IP column (if it still exists) and if they are different then save it and possibly inform the user via Email. This will minimise the size of the table too
Maybe start of with picking the correct data types before complaining about table size. Storage is cheap anyways nowadays.
Just because it is cheap doesn't mean you shouldn't try to minimise the size of the data.
Why are u using varchar for userId ? Why not use int(11)
Also why are you throw public error for any one to see ? maybe add check for if production or not ?
You can't use mysqli* with Rev, unless you want to waste time converting the whole damn cms to PHP 7 which is useless; as it's all a retarded pile of outdated code.I was about to say the same thing.
And
Code:mysql_query()