-
-
final class UserLogin {
- public function __construct() {
- } ; 🎜 >
public static function getUserInfo() {
- if (isset($_COOKIE["user_id"])&&$_COOKIE["user_id"]&&(trim($_COOKIE["user_id"])!=""user_id"]&&(trim($_COOKIE["user_id"])!=" " )) {
- if (isset($_SESSION["USER_INFO"]))
- return $_SESSION["USER_INFO"];
- $dao = new UserDao();find ($_COOKIE["user_id"]);
- if ($user) {
- $_SESSION["USER_INFO"] = $user;
- setcookie("docloud_sid", session_id(), time () + 36000);
- setcookie("user_id", $_COOKIE["user_id"], time() + 36000);
-
- if (array_key_exists("selected_prj_id", $ setcookie( "selected_prj_id", $_COOKIE["selected_prj_id"], time() + 36000);
-
- if (array_key_exists("selected_class_id"ookie_lectse_class_id"),Cone_pateSp生活)" $ _COOKIE[" selected_class_id"], time() + 36000);
-
- if (array_key_exists("selected_image_id", $_COOKIE))
- setcookieage("selected_image")" time () + 36000);
-
- if (array_key_exists("test_image_ids", $_COOKIE))
- setcookie("test_image_ids", $_COOKIE["test_image_idsookie("test_image_ids", $_COOKIE["test_image_ids); 🎜 >
- if (array_key_exists("upload_image_ids", $_COOKIE))
- setcookie("upload_image_ids", $_COOKIE["upload_image_ids"], time(user. > }
- }
- self::clearCookie();
- 回傳null;
- }
public static function setUserInfo($userInfo) {
- $_SESSION [ "USER_INFO"] = $userInfo;
- setcookie("docloud_sid", session_id(), time() + 36000);
- setcookie("user_id ", $InfoInfo->getId(), time() + 36000 );
- }
public static function isLogin() {
- if (self::getUserInfo()) {
- return true;
- }
- return false;
- }
- 公用靜態函數delUserInfo() {
- self::clearCookie();
- session_destroy();
- }
-
- 靜態靜態函式clearCookie() {
- setcookie("docloud_sid", "", time() - 36000);
- setcookie("user_id", "", time() - 36000);
- setcookie ( "selected_prj_id", "", time() - 36000);
- setcookie("selected_class_id", "", time() - 36000);
- setcookie("selected_image_id", "", time( 36000 );
- setcookie("test_image_ids", "", time( ) - 36000);
- setcookie("upload_image_ids", "", time() - 36000);
- ?>
-
-
-
- 複製程式碼
-
-
2、在使用者輸入使用者名稱、密碼處呼叫一個相關判定
-
-
require_once 'Init.php';
if (UserLogin::isLogin() && $_COOKIE["user_id"]==1) {
- UserLogin::delUserInfo();
- }
- else if (UserLogin ::isLogin()){
- Utils::redirect('welcome');
- }
$使用者名稱= null;
- $密碼= null; p>
$msg = "";
if (isset($_POST['使用者名稱']) && isset($_POST[ '密碼'])) {
- $username = addslashes(trim(stripslashes($_POST ['用戶名'])));
- $password = addslashes(trim(stripslashes($_POST ['密碼'])) ));
- // 驗證
- $errors = LoginValidator::validate($username, $password);
-
- if (empty($errors)) {
- // 儲存
- $dao = new UserDao();
- $user = $dao->findByName($username);
- $last_login_ip = Utils::getIpAddress();
- $user->setLastLoginIp($ last_login_ip); now = new DateTime();
- $user->setLastLoginTime($now);
- $dao->save($user);
- UserLogin::setUserInfo( $user);
- Flash: :addFlash('登入成功!');
- Utils::redirect('welcome');
- }
-
- foreach ($errors as $e) {
- $msg .= $msg .= $msg . e->getMessage()."
";
- }
- }
- ?>
-
-
複製程式碼
|