Browse Source

ip storing in session, #13

git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/branches/evo@147 4cb57b5f-5bbd-dd11-951b-001d605cbbc5
master
pzinovkin 15 years ago
parent
commit
117943f524
  1. 2
      model/DbDriver.php
  2. 8
      session/Session.model.php
  3. 22
      session/session.sql

2
model/DbDriver.php

@ -173,7 +173,7 @@ abstract class DbDriver
public function quoteInto($text, $value) public function quoteInto($text, $value)
{ {
$pos = strpos($text, '?');
$pos = mb_strpos($text, '?');
if ($pos === false) { if ($pos === false) {
return $text; return $text;
} }

8
session/Session.model.php

@ -43,9 +43,11 @@ class SessionModel extends Model
preg_match('/user\|.+s:2:"id";s:(\d+):"(\d+)"/', $data, $match); preg_match('/user\|.+s:2:"id";s:(\d+):"(\d+)"/', $data, $match);
$user_id = empty($match) ? 0 : (int) $match[2]; $user_id = empty($match) ? 0 : (int) $match[2];
$sql = 'INSERT INTO ' . $this->table() . ' (`id`, `expires`, `user_id`, `data`)'
. ' VALUES(' . $this->quote($id) . ', UNIX_TIMESTAMP() + ' . (int) $this->life_time . ', ' . $user_id . ', ' . $this->quote($data) . ')'
. ' ON DUPLICATE KEY UPDATE `expires`=UNIX_TIMESTAMP() + ' . (int) $this->life_time . ', `user_id`=' . $user_id . ', `data`=' . $this->quote($data);
$ip = Env::Server('HTTP_X_FORWARDED_FOR', Env::Server('REMOTE_ADDR'));
$sql = 'INSERT INTO ' . $this->table() . ' (`id`, `expires`, `ip`, `user_id`, `data`)'
. ' VALUES(' . $this->quote($id) . ', UNIX_TIMESTAMP() + ' . (int) $this->life_time . ', INET_ATON(' . $this->quote($ip) . '), ' . $user_id . ', ' . $this->quote($data) . ')'
. ' ON DUPLICATE KEY UPDATE `expires`=UNIX_TIMESTAMP() + ' . (int) $this->life_time . ', `ip`=INET_ATON(' . $this->quote($ip) . '), `user_id`=' . $user_id . ', `data`=' . $this->quote($data);
$affected = $this->db->query($sql)->affectedRows(); $affected = $this->db->query($sql)->affectedRows();
return (bool) ($this->getInsertId()) ? $this->getInsertId() : $affected; return (bool) ($this->getInsertId()) ? $this->getInsertId() : $affected;
} }

22
session/session.sql

@ -1,10 +1,16 @@
--
-- $Id$
--
CREATE TABLE IF NOT EXISTS `session` (
`id` char(32) NOT NULL,
`expires` int(11) unsigned NOT NULL,
`user_id` int(11) unsigned DEFAULT '0',
`data` text NOT NULL,
DROP TABLE IF EXISTS `session`;
CREATE TABLE `session` (
`id` CHAR( 32 ) NOT NULL ,
`expires` INT UNSIGNED NOT NULL ,
`ip` INT UNSIGNED NOT NULL ,
`user_id` INT UNSIGNED NOT NULL DEFAULT 0,
`data` TEXT NOT NULL ,
PRIMARY KEY ( `id` ) , PRIMARY KEY ( `id` ) ,
KEY `expires` (`expires`),
KEY `user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INDEX `expires` ( `expires` ) ,
INDEX `user_id` ( `user_id` )
) ENGINE = InnoDB DEFAULT CHARACTER SET = utf8;
Loading…
Cancel
Save