GEncrypt.inc.php:
class GEncrypt extends GSuperclass {
protected static function keyED($txt,$encrypt_key){
$encrypt_key = md5($encrypt_key);
$ctr=0;
$tmp = "";
for ($i=0;$i
if ($ctr==strlen($encrypt_key)) $ctr=0;
$tmp.= substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1);
$ctr++;
}
return $tmp;
}
public static function encrypt($txt,$key){
//$encrypt_key = md5(rand(0,32000));
$encrypt_key = md5(((float) date("YmdHis") + rand(10000000000000000,99999999999999999)).rand(100000,999999));
$ctr=0;
$tmp = "";
for ($i=0;$i
if ($ctr==strlen($encrypt_key)) $ctr=0;
$tmp.= substr($encrypt_key,$ctr,1) . (substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1));
$ctr++;
}
return base64_encode(self::keyED($tmp,$key));
}
public static function decrypt($txt,$key){
$txt = self::keyED( base64_decode($txt),$key);
$tmp = "";
for ($i=0;$i
$md5 = substr($txt,$i,1);
$i++;
$tmp.= (substr($txt,$i,1) ^ $md5);
}
return $tmp;
}
}
GToken.inc.php
·½·¨:
a,granteToken ²ÎÊý:formName,¼´¶¯×÷Ãû³Æ,keyÊǼÓÃÜ/½âÃÜ ÃÜÔ¿.
·µ»ØÒ»¸ö×Ö·û´®,ÐÎʽÊÇ: ¼ÓÃÜ(formName:session_id)
b,isToken ²ÎÊý:token ¼´granteToken²úÉúµÄ½á¹û,formName,¶¯×÷Ãû³Æ,fromCheckÊÇ·ñ¼ì²éÀ´Â·,Èç¹ûΪÕæ,»¹ÒªÅжÏtokenÀïµÄsession_idÊÇ·ñºÍµ±Ç°µÄsession_idÒ»ÖÁ.
c,dropToken,µ±³É¹¦Ö´ÐÐÒ»¸ö¶¯×÷ºó,µ÷ÓÃÕâ¸öº¯Êý,°ÑÕâ¸ötoken¼ÇÈësessionÀï,
/**
* ÔÀí£ºÇëÇó·ÖÅätokenµÄʱºò£¬Ïë°ì·¨·ÖÅäÒ»¸öΨһµÄtoken, base64( time + rand + action)
* Èç¹ûÌá½»£¬½«Õâ¸ötoken¼Ç¼£¬ËµÃ÷Õâ¸ötokenÒԾʹÓ㬿ÉÒÔ¸ú¾ÝËüÀ´±ÜÃâÖظ´Ìá½»¡£
*
*/
class GToken {
/**
* µÃµ½µ±Ç°ËùÓеÄtoken
*
* @return array
*/
public static function getTokens(){
$tokens = $_SESSION[GConfig::SESSION_KEY_TOKEN ];
if (empty($tokens) && !is_array($tokens)) {
$tokens = array();
}
return $tokens;
}
/**
* ²úÉúÒ»¸öеÄToken
*
* @param string $formName
* @param ¼ÓÃÜÃÜÔ¿ $key
* @return string
*/
public static function granteToken($formName,$key = GConfig::ENCRYPT_KEY ){
$token = GEncrypt::encrypt($formName.":".session_id(),$key);
return $token;
}
/**
* ɾ³ýtoken,ʵ¼ÊÊÇÏòsession µÄÒ»¸öÊý×éÀï¼ÓÈëÒ»¸öÔªËØ£¬ËµÃ÷Õâ¸ötokenÒԾʹÓùý£¬ÒÔ±ÜÃâÊý¾ÝÖظ´Ìá½»¡£
*
* @param string $token
*/
public static function dropToken($token){
$tokens = self::getTokens();
$tokens[] = $token;
GSession::set(GConfig::SESSION_KEY_TOKEN ,$tokens);
}
/**
* ¼ì²éÊÇ·ñΪָ¶¨µÄToken
*
* @param string $token Òª¼ì²éµÄtokenÖµ
* @param string $formName
* @param boolean $fromCheck ÊÇ·ñ¼ì²éÀ´Â·,Èç¹ûΪtrue,»áÅжÏtokenÖи½¼ÓµÄsession_idÊÇ·ñºÍµ±Ç°session_idÒ»ÖÁ.
* @param string $key ¼ÓÃÜÃÜÔ¿
* @return boolean
*/
public static function isToken($token,$formName,$fromCheck = false,$key = GConfig::ENCRYPT_KEY){
$tokens = self::getTokens();
if (in_array($token,$tokens)) //Èç¹û´æÔÚ£¬ËµÃ÷ÊÇÒÔʹÓùýµÄtoken
return false;
$source = split(":", GEncrypt::decrypt($token,$key));
if($fromCheck)
return $source[1] == session_id() && $source[0] == $formName;
else
return $source[0] == $formName;
}
}
Ê×ÏÈ´Ó$_POSTÀïÈ¡³ötoken,ÓÃisTokenÅжÏ.
include("../common.inc.php");
$token = $_POST["token"];
if (GToken::isToken($token,"adminLogin",true)) {
$vCode = $_POST["vCode"];
if (strtoupper($vCode) != strtoupper($_SESSION[GConfig::SESSION_KEY_VALIDATE_CODE ])) {
throw new Exception("ÑéÖ¤Âë²»ÕýÈ·!");
}
$vo = new VO_Admin();
$vo->setNickName($_POST["name"]);
$vo->setPwd($_POST["pwd"]);
$mo = new MO_Admin();
$mo->setVO($vo);
$f = $mo->login();
if(!$f){
throw new Exception("Óû§Ãû»òÃÜÂë²»ÕýÈ·!");
}else{
GToken::dropToken($token);
//header("location:".GDir::getRelativePath("/admin/index.php"));
echo "here"; //Èç¹ûÊÇÍⲿÌá½»µÄ,Õâ¾ä¾Í²»»á´òÓ¡³öÀ´!
}
}
$sFile = GDir::getAbsPath(GConfig::DIR_SERIALIZE ,"admin/login");
$tpl = GSerialize::load($sFile);
if ($tpl === false) {
$tpl = new GTpl(GConfig::DIR_SKIN ,GConfig::DEBUG_TPL_FILE );
$tpl->load(array(
"header" => "admin/header.html",
"footer" => "admin/footer.html",
"admLogin" => "admin/login.html",
"admLoginJs"=> "admin/loginJs.html"
));
GSerialize::save($tpl,$sFile);
}
$tpl->assign("title","¹ÜÀíÔ±µÇ½");
$tpl->assign("path",GDir::getRelativePath(SITE_DIR));
$tpl->assign("vImg",GDir::getRelativePath("/vImg.php"));
if (MO_Admin::isLogined()) {
$tpl->parseBlock("blk_logined");
}else {
$tpl->assign("token",GToken::granteToken("adminLogin"));
$tpl->parseBlock("blk_loadScripts","cond_notLogin");
$tpl->parseBlock("blk_notLogin");
}
echo $tpl->parse("header");
echo $tpl->parse("admLogin");
echo $tpl->parse("footer");
echo $tpl->parse("admLoginJs"); Webjx.Com
ÍƼöÐÅÏ¢
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- php³£ÓÃÕýÔò±í´ïʽ
- phpÐÔÄܼà²âÄ£¿éXHProf
- ÈÃCI¿ò¼ÜÖ§³Öservice²ã
- ʹÓÃPHPÉú³É´øLOGOµÄ¸öÐÔ»¯¶þάÂëͼÏñ
- ¹ØÓÚCodeIgniterÄã¿ÉÄܲ»ÖªµÀµÄ5¸ö֪ʶµã
- Memcache ºÁÃ뼶³¬Ê±¼°ÆäËû³£¼ûÎÊÌâ»ã×Ü
- [PHP±Ê¼Ç]PHPQueryÒ»¸ö´¦ÀíDOMµÄÀûÆ÷
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- PHP»ñÈ¡Óû§µÄÕæʵIP£¬²¢ÅжÏÊÇ·ñÄÚÍøIP
- PHP ´íÎóÈÕÖ¾ error_log
- ÀûÓÃbigpipe»úÖÆʵÏÖÒ³ÃæÄ£¿éµÄÒì²½äÖȾ chunked¼¼Êõ
- php¿ØÖÆÎļþÏÂÔØËÙ¶È
- js + php ¶ÁÈ¡¡¢²¥·ÅÊÓƵÁ÷ ¼æÈÝfirefox£¬c....
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- UNICODE Óë UTF-8 µÄ¹Øϵ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- phpʹÓÃmb_detect_encoding¼ì²â×Ö·û´®±àÂë
ÆÀÂÛ