phpnuxbill/system/autoload/Admin.php

47 lines
1.2 KiB
PHP
Raw Normal View History

2017-03-11 03:51:06 +08:00
<?php
/**
2023-10-12 16:55:42 +08:00
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
* by https://t.me/ibnux
**/
2017-03-11 03:51:06 +08:00
Class Admin{
2024-02-12 10:45:44 +08:00
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);
}
}
2024-02-23 15:40:47 +08:00
public static function _info($id = 0){
2024-02-23 15:52:10 +08:00
if(empty($id) && $id==0){
2024-02-23 15:40:47 +08:00
$id = Admin::getID();
}
return ORM::for_table('tbl_users')->find_one($id);
2017-03-11 03:51:06 +08:00
}
}