phpcms/modules/member/里新建MY_index.php 内容如下:
<?php
defined('IN_PHPCMS') or exit('No permission resources.');
class MY_index extends index {
private $times_db;
public function __construct() {
parent::__construct();
}
public function top_mini() {
$_username = param::get_cookie('_username');
$_userid = param::get_cookie('_userid');
$siteid = isset($_GET['siteid']) ? intval($_GET['siteid']) : '';
$jsoncallback=isset($_GET['jsoncallback']) ? $_GET['jsoncallback'] : '';
//定义站点id常量
if (!defined('SITEID')) {
define('SITEID', $siteid);
}
if($_username){
$res["success"]=1;
$res["message"]=' '.L('hellow').'<a href="'.APP_PATH.'member-account_manage_avatar.html" target="_blank">;<img style="display:inline;vertical-align: middle;padding:1px;width:16px;height:16px;border-radius:100%;border:1px solid #dedede;" src="'.get_memberavatar($_userid,1,30).'" width="16" height="16" onerror="this.src=\''.IMG_PATH.'member/nophoto.gif\'">;</a>; '.get_nickname().' 欢迎回家 <a href="'.APP_PATH.'member-index.html" target="_blank">;'.L('member_center').'</a>; | <a href="'.APP_PATH.'member-fabu.html" target="_top" class="upv_btn">;发布信息</a>; | <a href="'.APP_PATH.'member-logout.html">;'.L('logout').'</a>;';
$res["message"] = pc_base::load_config('system', 'charset') == 'gbk' ? iconv('utf-8', 'utf-8', $res["message"]) : $res["message"];
//get_nickname();//,
}
else{
$res["success"]=0;
}
if($jsoncallback){
echo $jsoncallback . "({\"items\":[".json_encode($res)."]})";
}else{
echo json_encode($res);
}
//echo json_encode($res);
}
}
?>
新建或者加到其他JS里:
ajax={
isIE:!-[1,],
TRANS_ID:1000,
head:document.getElementsByTagName("head")[0],
request:function(method,url,cb,data,options){
if(options){
var hs=options.headers;
if(hs){for(var h in hs){if(hs.hasOwnProperty(h))this.initHeader(h,hs[h],false)}}
}
if(typeof data=="object"){data.ajax=1;data=this.urlEncode(data)}else{if(data)data+='&';else data='';data+='ajax=1';}
method=method.toUpperCase();
if(method=='GET'&&data){url+=(url.indexOf('?')!=-1?'&':'?')+data+'&excmstime='+(new Date().getTime())}
var m=url.match(/.*\:\/\/([^\/]*).*/);
var domain=typeof m != "undefined" && m != null ? m[1] : url;
if(m && domain != document.domain){ // cross domain
if(method=='POST'&&data){if(url.indexOf('?')<0)url+='?';url+=data}
var transId = ++this.TRANS_ID;
var trans = {
id:transId,
cb:"crossDomainCallback"+transId,
scriptId:"crossDomainScript"+transId,
url:url,
callback:cb
};
var conn=this;
window[trans.cb]=function(o){conn.handleResponse(o,trans)};
url += '&crossDomainCallback=' + trans.cb;
var script = document.createElement("script");
script.setAttribute("src", url);
script.setAttribute("type", "text/javascript");
script.setAttribute("id", trans.scriptId);
this.head.appendChild(script);
}else{
return this.asyncRequest(method,url,cb,data);
}
},
serializeForm:function(f){
if(typeof f=='string')f=(document.getElementById(f)||document.forms[f])
var el,name,val,disabled,data='',hasSubmit=false;
for(var i=0; i < f.elements.length; i++){
el=f.elements[i];
disabled=f.elements[i].disabled;
name=f.elements[i].name;
val=f.elements[i].value;
if(!disabled&&name){
switch(el.type){
case 'select-one':
case 'select-multiple':
for(var j=0;j<el.options.length;j++){if(el.options[j].selected){if(this.isIE){data+=encodeURIComponent(name)+'='+encodeURIComponent(el.options[j].attributes['value'].specified?el.options[j].value:el.options[j].text)+'&'}else{data+=encodeURIComponent(name)+'='+encodeURIComponent(el.options[j].hasAttribute('value')?el.options[j].value:el.options[j].text)+'&'}}}
break;
case 'radio':
case 'checkbox':if(el.checked){data+=encodeURIComponent(name)+'='+encodeURIComponent(val)+'&'}break;
case 'file':
case undefined:
case 'reset':
case 'button':break;
case 'submit':if(hasSubmit == false){data+=encodeURIComponent(name)+'='+encodeURIComponent(val)+'&';hasSubmit=true}break;
default:data+=encodeURIComponent(name)+'='+encodeURIComponent(val)+'&'; break;
}
}
}
data=data.substr(0,data.length - 1);
return data;
},
asyncRequest:function(method,uri,callback,postData){
var o=this.getConnectionObject();
if(!o){return null}
else{
o.conn.open(method,uri,true);
if(this.useDefaultXhrHeader){if(!this.defaultHeaders['X-Requested-With']){this.initHeader('X-Requested-With',this.defaultXhrHeader,true)}}
if(postData&&this.useDefaultHeader &&(!this.hasHeaders||!this.headers['Content-Type'])){this.initHeader('Content-Type',this.defaultPostHeader)}
if(this.hasDefaultHeaders||this.hasHeaders){this.setHeader(o)}
this.handleReadyState(o,callback);
o.conn.send(postData||null);
return o;
}
},
headers:{},
hasHeaders:false,
useDefaultHeader:true,
defaultPostHeader:'application/x-www-form-urlencoded; charset=UTF-8',
useDefaultXhrHeader:true,
defaultXhrHeader:'XMLHttpRequest',
hasDefaultHeaders:true,
defaultHeaders:{},
poll:{},
timeout:{},
pollInterval:50,
transactionId:0,
setProgId:function(id){this.activeX.unshift(id);},
setDefaultPostHeader:function(b){this.useDefaultHeader=b},
setDefaultXhrHeader:function(b){this.useDefaultXhrHeader=b},
setPollingInterval:function(i){if(typeof i=='number'&&isFinite(i))this.pollInterval=i},
createXhrObject:function(transactionId){
var obj,http;
try{http=new XMLHttpRequest();obj={conn:http,tId:transactionId}}
catch(e){for(var i=0;i<this.activeX.length;++i){try{http=new ActiveXObject(this.activeX[i]);obj={conn:http,tId:transactionId};break}catch(e){}}}
finally{return obj}
},
getConnectionObject:function(){
var o;
var tId=this.transactionId;
try{o=this.createXhrObject(tId);if(o){this.transactionId++}}catch(e){}finally{return o}
},
handleReadyState:function(o,callback){
var oConn=this;
if(callback&&callback.timeout){this.timeout[o.tId]=window.setTimeout(function(){oConn.abort(o,callback,true)},callback.timeout)}
this.poll[o.tId]=window.setInterval(
function(){
if(o.conn&&o.conn.readyState == 4){
window.clearInterval(oConn.poll[o.tId]);
delete oConn.poll[o.tId];
if(callback&&callback.timeout){window.clearTimeout(oConn.timeout[o.tId]);delete oConn.timeout[o.tId]}
oConn.handleTransactionResponse(o,callback);
}
},this.pollInterval);
},
handleTransactionResponse:function(o,callback,isAbort){
if(!callback){this.releaseObject(o);return}
var httpStatus,responseObject;
try{if(o.conn.status !== undefined&&o.conn.status != 0){httpStatus=o.conn.status}else{httpStatus=13030}}catch(e){httpStatus=13030}
if(httpStatus>=200&&httpStatus<300){
responseObject=this.createResponseObject(o,callback.argument);
if(callback.success){if(!callback.scope){callback.success(responseObject)}else{callback.success.apply(callback.scope,[responseObject])}}
}
else{
switch(httpStatus){
case 12002:
case 12029:
case 12030:
case 12031:
case 12152:
case 13030:
responseObject=this.createExceptionObject(o.tId,callback.argument,(isAbort?isAbort:false));
if(callback.failure){if(!callback.scope){callback.failure(responseObject)}else{callback.failure.apply(callback.scope,[responseObject])}}
break;
default:
responseObject=this.createResponseObject(o,callback.argument);
if(callback.failure){if(!callback.scope){callback.failure(responseObject)}else{callback.failure.apply(callback.scope,[responseObject])}}
}
}
this.releaseObject(o);
responseObject=null;
},
createResponseObject:function(o,callbackArg){
var obj={};
var headerObj={};
try{
var headerStr=o.conn.getAllResponseHeaders();
var header=headerStr.split('\n');
for(var i=0; i < header.length; i++){
var delimitPos=header[i].indexOf(':');
if(delimitPos != -1){headerObj[header[i].substring(0,delimitPos)]=header[i].substring(delimitPos+2)}
}
}
catch(e){}
obj.tId=o.tId;
obj.status=o.conn.status;
obj.statusText=o.conn.statusText;
obj.getResponseHeader=headerObj;
obj.getAllResponseHeaders=headerStr;
obj.responseText=o.conn.responseText;
obj.responseXML=o.conn.responseXML;
if(typeof callbackArg !== undefined){obj.argument=callbackArg}
return obj;
},
createExceptionObject:function(tId,callbackArg,isAbort){
var COMM_CODE=0;
var COMM_ERROR='communication failure';
var ABORT_CODE=-1;
var ABORT_ERROR='transaction aborted';
var obj={};
obj.tId=tId;
if(isAbort){obj.status=ABORT_CODE;obj.statusText=ABORT_ERROR}else{obj.status=COMM_CODE;obj.statusText=COMM_ERROR}
if(callbackArg){obj.argument=callbackArg}
return obj;
},
initHeader:function(label,value,isDefault){
var headerObj=(isDefault)?this.defaultHeaders:this.headers;
if(headerObj[label]===undefined){headerObj[label]=value}else{headerObj[label]=value+","+headerObj[label]}
if(isDefault){this.hasDefaultHeaders=true}else{this.hasHeaders=true}
},
setHeader:function(o){
if(this.hasDefaultHeaders){
for(var prop in this.defaultHeaders){
if(this.defaultHeaders.hasOwnProperty(prop)){o.conn.setRequestHeader(prop,this.defaultHeaders[prop])}
}
}
if(this.hasHeaders){
for(var prop in this.headers){
if(this.headers.hasOwnProperty(prop)){o.conn.setRequestHeader(prop,this.headers[prop])}
}
this.headers={};
this.hasHeaders=false;
}
},
resetDefaultHeaders:function(){
delete this.defaultHeaders;
this.defaultHeaders={};
this.hasDefaultHeaders=false;
},
abort:function(o,callback,isTimeout){
if(this.isCallInProgress(o)){
o.conn.abort();
window.clearInterval(this.poll[o.tId]);
delete this.poll[o.tId];
if(isTimeout){delete this.timeout[o.tId]}
this.handleTransactionResponse(o,callback,true);
return true;
}
else{return false}
},
isCallInProgress:function(o){if(o.conn){return o.conn.readyState!=4&&o.conn.readyState!=0}else{return false}},
releaseObject:function(o){o.conn=null;o=null},
activeX:['MSXML2.XMLHTTP.3.0','MSXML2.XMLHTTP','Microsoft.XMLHTTP'],
urlEncode:function(o){
if(!o){return ""}
var buf=[];
for(var key in o){
var ov=o[key],k=encodeURIComponent(key);
var type=typeof ov;
if(type == 'undefined'){buf.push(k,"=&")}
else if(type != "function"&&type != "object"){buf.push(k,"=",encodeURIComponent(ov),"&")}
else if(this.isArray(ov)){if(ov.length){for(var i=0,len=ov.length;i<len;i++){buf.push(k,"=",encodeURIComponent(ov[i]===undefined?'':ov[i]),"&")}}else{buf.push(k,"=&")}}
}
buf.pop();
return buf.join("");
},
isArray:function(v){return v&&typeof v.length=='number'&&typeof v.splice=='function'},
jsondecode:function(json){if(typeof json=='object')return json;try{return eval("("+json+")")}catch(e){return{}}},
update:function(element,method,uri,data,callback,msgtxt){
var tthis=this;
if(typeof element!=='object') element=this.getDom(element);
if(!element){alert('Lack Element');return}
var msg = document.createElement('div');
msg.className = 'ajaxloading';
msg.innerHTML = msg.title = msgtxt || 'Loading...';
element.firstChild ? element.insertBefor(msg, element.firstChild) : element.appendChild(msg);
this.request(method,uri,{success:function(response){
tthis.setInnerHTML(element, response.responseText);
if(callback){if(typeof(callback) == 'function'){callback()}else{try{eval(callback)}catch(e){}}}
}},data);
},
getDom:function(o){if(document.getElementById&&document.getElementById(o)){return document.getElementById(o)}else if(document.all&&document.all(o)){return document.all(o)}else if(document.layers&&document.layers[o]){return document.layers[o]}else{return false}},
destroyTrans:function(trans, isLoaded){
this.head.removeChild(document.getElementById(trans.scriptId));
//clearTimeout(trans.timeoutId);
if(isLoaded){window[trans.cb] = undefined;try{delete window[trans.cb];}catch(e){}}
else{window[trans.cb] = function(){window[trans.cb]=undefined;try{delete window[trans.cb]}catch(e){}}}
},
handleResponse : function(o, trans){
this.trans = false;
this.destroyTrans(trans, true);
if(trans.callback.success)trans.callback.success({responseText:o});
},
setInnerHTML : function (el, html){
var ua = navigator.userAgent.toLowerCase();
if (ua.indexOf('msie') >= 0 && ua.indexOf('opera') < 0) {
html = '<div style="display:none">for IE</div>' + html;
html = html.replace(/<script([^>]*)>/gi, '<script$1 defer>');
el.innerHTML = html;
el.removeChild(el.firstChild);
}else{
var el_next = el.nextSibling;
var el_parent = el.parentNode;
el_parent.removeChild(el);
el.innerHTML = html;
el_next ? el_parent.insertBefore(el, el_next) : el_parent.appendChild(el);
}
}
};
}}catch(e){}
try{document.execCommand('BackgroundImageCache',false,true);}catch(e){}
var isIE=!-[1,];
var isGecko=(navigator.userAgent.indexOf("Gecko")>-1)&&(navigator.userAgent.indexOf("KHTML")==-1);
function $_(o){if(document.getElementById&&document.getElementById(o)){return document.getElementById(o);}else if (document.all&&document.all(o)){return document.all(o);}else if (document.layers&&document.layers[o]){return document.layers[o];}else{return false;}}
function setCls(o,c,f){if(!o)return;var oc=o.className=o.className.replace(new RegExp('( ?|^)'+c+'\\b'),'');if(!f)o.className=oc.length>0?(oc+' '+c):c}
String.prototype.trim= function(){return this.replace(/(^\s*)|(\s*$_)/g,"");}
if(!Array.prototype.indexOf)Array.prototype.indexOf=function(item,i){i||(i=0);var l=this.length;if(i<0)i=l+i;for(;i<l;i++)if(this[i]===item)return i;return -1}
function isEmail(s){var p=/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;return p.test(s)}
function isUrl(s){var p=new RegExp("((^http)|(^https)):\/\/(\\w)+\.(\\w)+");return p.test(s)}
function onEvent(A,B,C){B=B.replace(/^on/,'').toLowerCase();if(A.attachEvent){A[B+C]=function(){C.call(A,window.event)};A.attachEvent('on'+B,A[B+C])}else A.addEventListener(B,C,false);return A}
function unEvent(A,B,C){B=B.replace(/^on/,'').toLowerCase();if(A.attachEvent){A.detachEvent('on'+B,A[B+C]);A[B+C]=null}else A.removeEventListener(B,C,false);return A}
function show(){this.style.display='block'}
function hide(){this.style.display='none'}
function setVisibile(A,B){if(typeof A=='string')A=$_(A);if(A)A.style.display=B?'block':'none'}
function bytes(s){if(typeof(s)!="string"){s=s.value}var l=0;for(var i=0;i<s.length;i++){if(s.charCodeAt(i)>127){l++}l++}return l}
function preloadImage(){var args = preloadImage.arguments;if(!document.preloadImageArray)document.preloadImageArray=[];for(var i=0,len=args.length;i<args;i++){document.preloadImageArray.push(new Image());document.preloadImageArray[document.preloadImageArray.length].src=args[i]}}
function Extend(A,B){for(var C in B){A[C]=B[C]}return A}
function CurrentStyle(A){return A.currentStyle||document.defaultView.getComputedStyle(A,null)}
function Bind(A,B){var C=Array.prototype.slice.call(arguments).slice(2);return function(){return B.apply(A,C.concat(Array.prototype.slice.call(arguments)))}}
function forEach(A,B,C){if(A.forEach){A.forEach(B,C)}else{for(var i=0,len=A.length;i<len;i++)B.call(C,A[i],i,A)}}
var Tween={Quart:{easeOut:function(t,b,c,d){return-c*((t=t/d-1)*t*t*t-1)+b}},Back:{easeOut:function(t,b,c,d,s){if(s==undefined)s=1.70158;return c*((t=t/d-1)*t*((s+1)*t+s)+1)+b}},Bounce:{easeOut:function(t,b,c,d){if((t/=d)<(1/2.75)){return c*(7.5625*t*t)+b}else if(t<(2/2.75)){return c*(7.5625*(t-=(1.5/2.75))*t+.75)+b}else if(t<(2.5/2.75)){return c*(7.5625*(t-=(2.25/2.75))*t+.9375)+b}else{return c*(7.5625*(t-=(2.625/2.75))*t+.984375)+b}}}}
Login = {
form : new Array,
login : false,
// check user is login
isLogin : function(url, form, type){
if(!url) return ;
var tthis = this;
url += url.indexOf('?') < 0 ? '?' : '&';
url += 'logintype=' + type+"&forward="+encodeURIComponent(location.href)+"&time="+new Date().getTime()+"&jsoncallback=?";
//alert(url);
$.getJSON(url,function (json){
//alert(json);
$.each(json.items, function(i){
if (json.items[0].success==1){
tthis.logined(form,json.items[0].message);
}
});
});
/*ajax.request('get', url, {success:function(r){
alert(r.responseText);
var v = ajax.jsondecode(r.responseText);
if(v && v.success == 1) tthis.logined(form, v.message);
}});
*/
},
// render login
logined : function(form, msg){
this.login = true;
if(typeof form != 'object'){
form = $_(form);
}
var account = document.createElement('div');
account.className = 'accountinfo';
account.innerHTML = msg;
form.parentNode.form = form;
form.parentNode.insertBefore(account, form);
form.account = account;
setVisibile(form, false);
},
// logout
logout : function(o, url){
if(!url) return ;
var tthis = this;
ajax.request('get', url, {success:function(r){
var v = ajax.jsondecode(r.responseText);
if(v && v.success == 1){
tthis.login = false;
var account = o.parentNode;
var form = account.parentNode.form||null;
if(form.username){
var u = form.username.value;
form.reset();
form.username.value = u;
}
setVisibile(form, true);
account.parentNode.removeChild(account);
if(v.logoutinfo)tthis.sysnLogin(v.logoutinfo);
}
}});
},
// submit login form
submit : function(A){
var flag = true;
if(A.username.value.trim() == ''){
A.username.focus();
setVisibile('username_valid',true);
flag = false;
}
if(A.password.value.trim() == ''){
A.password.focus();
setVisibile('password_valid',true);
flag = false;
}
if(flag){
var tthis = this;
ajax.request('post', A.attributes['action'].value, {success:function(r){
var v = ajax.jsondecode(r.responseText);
if(v && v.success == 1){
if (v.logininfo) tthis.sysnLogin(v.logininfo);
tthis.logined(A, v.message);
if(A.loginforward && A.loginforward.value != '') window.location.href = A.loginforward.value;
}else if(v.success == 0){
alert(v.message);
}else{
alert('请求æœåŠ¡å™¨å¼‚常,请ç¨å€™å†ç™»å½•')
}
}},ajax.serializeForm(A));
}
return false;
},
// sysn login
sysnLogin : function(msg){
var d = document.createElement('div');
document.body.appendChild(d);
ajax.setInnerHTML(d,msg);
},
// initial forward combo
forwardInit : function(A,B,C,D){
if(A.render) return ;
A.render = true;
if(typeof B == 'string') B = $_(B);
if(!B) return ;
A.L = B;
B.O = A;
A.L.eventEls = [A,A.L];
A.L.check = function(e){
if(!this.eventObj) return;
var t = window.event ? window.event.srcElement : e.target;
var d = 5;
while(d > 0){
if(this.eventObj.eventEls.indexOf(t) >= 0){return}
else if(t.parentNode){t=t.parentNode}
else break;
d--;
}
this.eventObj.hide();
}
A.L.show = function(){document.eventObj=this;onEvent(document,'click',this.check);this.style.display='block';this.isshow=true}
A.L.hide = function(){document.eventObj=null;onEvent(document,'click',this.check);setCls(this.O,'combo_o',1);this.style.display='none';this.isshow=false;}
A.onclick = function(){setCls(this,'combo_o');this.L.show()}
A.onmouseout = function(){if(!this.L.isshow)setCls(this,'combo_o',1)}
var LI = A.L.getElementsByTagName('li');
for(var I=0;I<LI.length;I++){
if(LI[I].className != 'bd'){
LI[I].onclick = function(){
$_(C).value = this.attributes['value'].value;
A.innerHTML = this.innerHTML;
this.parentNode.hide();
}
}
LI[I].onmouseover = function(){
if(this.className != 'bd') setCls(this,'hover');
}
LI[I].onmouseout = function(){
if(this.className != 'bd') setCls(this,'hover', true);
}
}
}
};
前台调用方式:
<form id="page_loginForm" class="login-form" action="https://passport.shuyanghao.cn/member-login.html" method="post">
<input name="logintype" type="hidden" value="page" />
<input id="forward" name="forward" type="hidden" value="https://www.shuyanghao.cn" />
沭阳论坛通行证 用户名: <input id="username" class="int" name="username" size="15" type="text" />
密码: <input id="password" class="int" name="password" size="15" type="password" />
<input id="dosubmit" class="input_bn" name="dosubmit" type="submit" value=" " />
<a href="https://passport.shuyanghao.cn/member-register.html" target="_blank" rel="noopener">注册账户</a> | <a href="https://passport.shuyanghao.cn/member-public_forget_password.html" target="_blank" rel="noopener">找回密码</a> | <a href="https://passport.shuyanghao.cn/member-public_qq_loginnew.html" target="_blank" rel="noopener"><img title="使用QQ登录" src="https://www.shuyanghao.cn/images/qq_5016.png" alt="使用QQ登录" width="50" height="16" /></a>
</form>
<script type="text/javascript">Login.isLogin('http://www.xxx.com/index.php?m=member&c=index&a=top_mini','page_loginForm','page');</script>
帮助很大! 前辈亲自指点的,很少感谢!