0, 'msg' => 'successful' ]; } else{ $data = [ 'code' => -1012, 'err_msg' => '用户名或密码错误!' ]; } exit(json_encode($data)); } //如果cookie的值和计算的key不一致,则没有权限 // if ( ($_SERVER['PHP_AUTH_PW'] !== $password) || ($_SERVER['PHP_AUTH_USER'] !== $username) ){ // header('WWW-Authenticate: Basic realm="Please verify."'); // header('HTTP/1.0 401 Unauthorized'); // exit("

认证失败!

"); // } // else{ // $key = md5($username.$password.$ip.'onenav'); // //设置cookie // setcookie("key", $key, time()+7 * 24 * 60 * 60,"/"); // header('location:index.php?c=admin'); // } //获取访客IP function getIP() { if (getenv('HTTP_CLIENT_IP')) { $ip = getenv('HTTP_CLIENT_IP'); } elseif (getenv('HTTP_X_FORWARDED_FOR')) { $ip = getenv('HTTP_X_FORWARDED_FOR'); } elseif (getenv('HTTP_X_FORWARDED')) { $ip = getenv('HTTP_X_FORWARDED'); } elseif (getenv('HTTP_FORWARDED_FOR')) { $ip = getenv('HTTP_FORWARDED_FOR'); } elseif (getenv('HTTP_FORWARDED')) { $ip = getenv('HTTP_FORWARDED'); } else { $ip = $_SERVER['REMOTE_ADDR']; } return $ip; } // 载入后台登录模板 require('templates/admin/login.php');