Open Sencillo  2015.003
Long live the simplicity of PHP
 All Data Structures Namespaces Functions
session.php
1 <?php
2 /*~ session.php
3 .---------------------------------------------------------------------------.
4 | Software: Sencillo Session |
5 | Version: 2015.003 |
6 | Contact: ph@mastery.sk |
7 | ------------------------------------------------------------------------- |
8 | Author: Bc. Peter Horváth (original founder) |
9 | Copyright (c) 2015, Bc. Peter Horváth. All Rights Reserved. |
10 | ------------------------------------------------------------------------- |
11 | License: Distributed under the General Public License (GPL) |
12 | http://www.gnu.org/licenses/gpl-3.0.html |
13 | This program is distributed in the hope that it will be useful - WITHOUT |
14 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
15 | FITNESS FOR A PARTICULAR PURPOSE. |
16 '---------------------------------------------------------------------------'
17 ~*/
28 {
29  private $i;
30  private $smarray;
31 
35  public function __construct()
36  {
37  session_start();
38  }
39 
45  public function sm_get($name)
46  {
47  if(is_array($name))
48  {
49  $this->i = 0;
50  $this->smarray = array();
51  while(sizeof($name)>$this->i)
52  {
53  $this->smarray[$this->i] = $_SESSION[$name[$this->i++]];
54  }
55  return $this->smarray;
56  }
57  else
58  {
59  return $_SESSION[$name];
60  }
61  }
62 
66  public function sm_destroy()
67  {
68  session_destroy();
69  }
70 }
71 
83 {
84  private $current_time;
85  private $sql;
86 
90  public function __construct()
91  {
92  $this->current_time = array('year'=>date('Y'),
93  'month'=>date('m'),
94  'day'=>date('d'),
95  'hour'=>date('H'),
96  'minute'=>date('i'),
97  'second'=>date('s'),
98  'session'=>date('YmdHis'));
99  }
100 
104  public function lm_install()
105  {
106  $this->sql='
107  CREATE TABLE IF NOT EXISTS `login` (
108  `id` bigint(20) NOT NULL AUTO_INCREMENT,
109  `userid` bigint(20) NOT NULL,
110  `sessionid` longtext NOT NULL,
111  `expiration` int(11) NOT NULL,
112  `perm` int(11) NOT NULL,
113  PRIMARY KEY (`id`)
114  ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=0;
115  ';
116  $mysql->openTable('login');
117  $mysql->write($this->sql);
118  $this->sql='
119  CREATE TABLE IF NOT EXISTS `users` (
120  `userid` bigint(20) NOT NULL AUTO_INCREMENT,
121  `name` longtext NOT NULL,
122  `pass` longtext NOT NULL,
123  `perm` int(4) NOT NULL,
124  PRIMARY KEY (`userid`)
125  ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=0;
126  ';
127  $mysql->openTable('users');
128  $mysql->write($this->sql);
129  }
130 
137  public function lm_addUser($name,$pass,$perm=1000)
138  {
139  $mysql->openTable('users');
140  $mysql->insert("'name',md5('$pass'),$perm");
141  }
142 }
143 /*
144  *
145  * error = 0; //system: OK - access granted
146  * error = null; //system: UNKNOWN STATUS, system continued
147  * error = 1; //system: I/O - ERROR email not exist
148  * error = 2; //system: I/O - ERROR password error
149  * error = 3; //system: DB - ERROR login structured data failed - AntiHack attention
150  *
151  * Session manipulation:
152  * ?s=exit //system get status NULL and unset access signature - system go to logout mode
153  *
154  */
155 //echo("<script>alert('Country:".USER_GEO.";User:".$_SESSION['userid'].";Status:".$error.";Cookies:[".$cookie1."],[".$cookie2."];Exp:".$LoginExp.";SessionID:".$_SESSION['sessionid']."');</script>");
156 ?>
sm_get($name)
Definition: session.php:45
lm_addUser($name, $pass, $perm=1000)
Definition: session.php:137