forked from kevinowino869/mitrobill
Session using cookie
This commit is contained in:
@ -6,8 +6,40 @@
|
||||
|
||||
|
||||
Class Admin{
|
||||
|
||||
public static function getID(){
|
||||
global $db_password;
|
||||
if(isset($_SESSION['aid'])){
|
||||
return $_SESSION['aid'];
|
||||
}else if(isset($_COOKIE['aid'])){
|
||||
// id.time.sha1
|
||||
$tmp = explode('.',$_COOKIE['aid']);
|
||||
if(sha1($tmp[0].$tmp[1].$db_password)==$tmp[2]){
|
||||
if($tmp[1] < 86400*7){
|
||||
$_SESSION['aid'] = $tmp[0];
|
||||
return $tmp[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static function setCookie($aid){
|
||||
global $db_password;
|
||||
if(isset($aid)){
|
||||
$time = time();
|
||||
setcookie('aid', $aid.'.'.$time.'.'.sha1($aid.'.'.$time.'.'.$db_password), time()+86400*7);
|
||||
}
|
||||
}
|
||||
|
||||
public static function removeCookie(){
|
||||
if(isset($_COOKIE['aid'])){
|
||||
setcookie('aid', '', time()-86400);
|
||||
}
|
||||
}
|
||||
|
||||
public static function _info(){
|
||||
$id = $_SESSION['aid'];
|
||||
$id = Admin::getID();
|
||||
$d = ORM::for_table('tbl_users')->find_one($id);
|
||||
return $d;
|
||||
}
|
||||
|
@ -8,9 +8,40 @@
|
||||
|
||||
class User
|
||||
{
|
||||
public static function getID(){
|
||||
global $db_password;
|
||||
if(isset($_SESSION['uid'])){
|
||||
return $_SESSION['uid'];
|
||||
}else if(isset($_COOKIE['uid'])){
|
||||
// id.time.sha1
|
||||
$tmp = explode('.',$_COOKIE['uid']);
|
||||
if(sha1($tmp[0].$tmp[1].$db_password)==$tmp[2]){
|
||||
if($tmp[1] < 86400*30){
|
||||
$_SESSION['uid'] = $tmp[0];
|
||||
return $tmp[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static function setCookie($uid){
|
||||
global $db_password;
|
||||
if(isset($uid)){
|
||||
$time = time();
|
||||
setcookie('uid', $uid.'.'.$time.'.'.sha1($uid.'.'.$time.'.'.$db_password), time()+86400*30);
|
||||
}
|
||||
}
|
||||
|
||||
public static function removeCookie(){
|
||||
if(isset($_COOKIE['uid'])){
|
||||
setcookie('uid', '', time()-86400);
|
||||
}
|
||||
}
|
||||
|
||||
public static function _info()
|
||||
{
|
||||
$id = $_SESSION['uid'];
|
||||
$id = User::getID();
|
||||
$d = ORM::for_table('tbl_customers')->find_one($id);
|
||||
|
||||
if(empty($d['username'])){
|
||||
@ -21,7 +52,7 @@ class User
|
||||
|
||||
public static function _billing()
|
||||
{
|
||||
$id = $_SESSION['uid'];
|
||||
$id = User::getID();
|
||||
$d = ORM::for_table('tbl_user_recharges')->where('customer_id', $id)->find_many();
|
||||
return $d;
|
||||
}
|
||||
|
Reference in New Issue
Block a user