function adminLogin() { global $cookie_key_admin; if (isset($_COOKIE['userId'], $_COOKIE['userName'], $_COOKIE['adminSecure'])) { $Sc = explode("|", Xxtea::decrypt($_COOKIE['adminSecure'], $cookie_key_admin)); if (isset($Sc[1], $Sc[0]) && $_COOKIE['userId'] == $Sc[1] && $_COOKIE['userName'] == $Sc[0]) { return true; } } return false; }
function Add_S(&$array) { if (is_array($array)) { foreach ($array as $key => $value) { if (!is_array($value)) { $array[$key] = addslashes($value); } else { Add_S($array[$key]); } } } } //设置游客cookie $anonymous = get_cookie('anonymous'); if (empty($anonymous)) { $xxtea = new Xxtea(); $auth = real_ip() . "\t" . $timestamp; $strcode = $xxtea->encrypt($auth, "zzqss"); set_cookie('anonymous', $strcode, $timestamp + 3600 * 24 * 7); //cookie有效期一周 $anonymous = $strcode; } checkauth(); //检查用户登录 checkkey(); //统计购物车物品数量 if (!empty($_USERS['uname'])) { $wherestrcart = "uname ='" . $_USERS['uname'] . "'"; } else { $wherestrcart = "anonymous ='" . $anonymous . "'"; }
/** +---------------------------------------------------------- * 解密字符串 * +---------------------------------------------------------- * @access static +---------------------------------------------------------- * @param string $str 字符串 * @param string $key 加密key +---------------------------------------------------------- * @return string +---------------------------------------------------------- * @throws ThinkExecption +---------------------------------------------------------- */ function decrypt($str, $key) { if ($str == "") { return ""; } $v = Xxtea::str2long($str, false); $k = Xxtea::str2long($key, false); $n = count($v) - 1; $z = $v[$n]; $y = $v[0]; $delta = 0x9e3779b9; $q = floor(6 + 52 / ($n + 1)); $sum = Xxtea::int32($q * $delta); while ($sum != 0) { $e = $sum >> 2 & 3; for ($p = $n; $p > 0; $p--) { $z = $v[$p - 1]; $mx = Xxtea::int32(($z >> 5 & 0x7ffffff ^ $y << 2) + ($y >> 3 & 0x1fffffff ^ $z << 4)) ^ Xxtea::int32(($sum ^ $y) + ($k[$p & 3 ^ $e] ^ $z)); $y = $v[$p] = Xxtea::int32($v[$p] - $mx); } $z = $v[$n]; $mx = Xxtea::int32(($z >> 5 & 0x7ffffff ^ $y << 2) + ($y >> 3 & 0x1fffffff ^ $z << 4)) ^ Xxtea::int32(($sum ^ $y) + ($k[$p & 3 ^ $e] ^ $z)); $y = $v[0] = Xxtea::int32($v[0] - $mx); $sum = Xxtea::int32($sum - $delta); } return Xxtea::long2str($v, true); }
function checkkey() { global $_CKEY; $_CKEY = 0; $auth_file = ROOT_PATH . "/domain_key.dat"; if (!file_exists($auth_file)) { return false; exit; } $str = @file_get_contents($auth_file); $xxtea = new Xxtea(); $jiamicode = pack('H*', $str); $strcode = $xxtea->decrypt($jiamicode, "zzqss"); $strcode = cookie_authcode($strcode, 'DECODE', "zzqss"); $strcode = base64_decode($strcode); list($shangye, $domainstr) = explode("@", $strcode); if (empty($domainstr) || empty($shangye)) { return false; } $strcode = unserialize($domainstr); $host = $_SERVER['HTTP_HOST']; if (!in_array($host, $strcode)) { return false; exit; } else { $_CKEY = 2; return true; } }
<?php require dirname(__FILE__) . "/global.php"; if (isset($_POST['nickname'])) { $nickname = strAddslashes(trim($_POST['nickname'])); if (!empty($nickname)) { $checkname = usernameCheck($nickname); if (!empty($checkname)) { echo "1 " . $checkname; } else { $DB->connect($mysql_host, $mysql_user, $mysql_pass, $mysql_dbname); $N = $DB->fetch_one("SELECT COUNT(`uid`) FROM `" . $table_member . "` WHERE lower(`name`)='" . strtolower($nickname) . "'"); $DB->close(); if ($N > 0) { echo "1 昵称“" . $nickname . "”已被注册,换一个吧 ^_^"; } else { setcookie("TouristName", Xxtea::encrypt($nickname, $cookie_key_login), time() + 63072000, $cookie_path, $cookie_domain); echo "0 成功"; } } } else { setcookie("TouristName", '', time() - 3600, $cookie_path, $cookie_domain); echo "1"; } } else { $tmp = template("anonymity.html"); $tmp->assign('loginArr', $loginArr); $tmp->output(); } ob_end_flush();