午夜91福利视频,午夜成人在线观看,午夜在线视频免费观看,午夜福利短视频,精品午夜成人免费视频APP

幫助

【教程】會員登錄后只顯示頭像的方法

2020-11-20 20:42 易優技巧

       很久沒寫(xie)教程(cheng)了,因為最近考試(shi)的原因暫(zan)時(shi)(shi)沒有(you)寫(xie)更多的教程(cheng),今天就來寫(xie)一個有(you)關(guan)易優會(hui)員登錄后(hou)頭像(xiang)(xiang)的問題,大(da)家在(zai)做(zuo)站(zhan)的時(shi)(shi)候(hou),會(hui)碰到,想登錄后(hou)只顯示頭像(xiang)(xiang)而不(bu)顯示賬號昵稱(cheng)或者用戶名。對于(yu)目前的邏輯,系(xi)統暫(zan)時(shi)(shi)還不(bu)能實現,只能應用于(yu){eyou:user type='info'}里面的 頭像(xiang)(xiang)加昵稱(cheng) 

 才可以。 這樣會(hui)碰到瓶(ping)頸,有的(de)模板(ban)需求(qiu)只要(yao) 單獨顯示頭像(xiang)就(jiu)好 不要(yao)顯示昵稱

 

 

可(ke)是你(ni)怎么調用是無法實現(xian)的。

 

 

所(suo)以這種的確 有點頭疼。小秋今天(tian)就利用(yong)user登錄(lu)會員標(biao)簽 來(lai)(lai)模擬復制一個(ge)邏輯出(chu)來(lai)(lai),來(lai)(lai)填(tian)充這個(ge)所(suo)謂(wei)的不足吧,

效果如下:

 

 

如果你想登錄顯示用戶名/昵稱(cheng)  你就正常(chang)的官方標簽即可。

如果你想登錄后只顯(xian)示頭像(xiang),那么就用(yong)以下標簽:

 

{eyou:users type='open'}

{eyou:users type='cart'}

        <a href="{$field.url}" id="{$field.id}" >購物車(<font color="red" id="{$field.cartid}">0</font>)</a>

       ;  {$field.hidden}

        {/eyou:users}

{eyou:users type='login'}

<a href=&quot;{$field.url}" id="{$field.id}">登(deng)錄(lu)</a> 

{$field.hidden}

{/eyou:users}

{eyou:users type='reg'}

<a href=&quot;{$field.url}" id="{$field.id}">注冊</a> 

{$field.hidden}

{/eyou:users}

{eyou:users type='logout'}

<a href="{$field.url}" id="{$field.id}">退(tui)出(chu)</a> 

{$field.hidden}

{/eyou:users}

{/eyou:users}

 

代碼有點多,因為是全新復制一個標簽的結果,但我相信可以結合代碼出來,只是不想費腦,就直接全新復制標簽出來了,請多見諒~希望官方后續整合下.

 

 

以下(xia)是(shi)修改的文(wen)件部(bu)分:

打開applicationapicontroller

Ajax.php  文件 打(da)開 大概在 (179行(xing) )

 

找到以下

 

    /**

     * 檢(jian)驗會員登錄

     */

    public function check_user()

    {

        if (IS_AJAX) {

            $type = input('param.type/s', 'default');

            $img = input('param.img/s');

            $users_id = session('users_id');

            if ('login' == $type) {

                if (!empty($users_id)) {

                    $currentstyle = input('param.currentstyle/s');

                    $users = M('users')->field('username,nickname,head_pic')

    &nbsp;                   ->where([

                            'users_id'  => $users_id,

                            'lang'      => $this->home_lang,  

        &nbsp;               ])->find();

              &nbsp;     if (!empty($users)) {

                        $nickname = $users['nickname'];

               ;         if (empty($nickname)) {

                            $nickname = $users['username'];

      &nbsp;                 }

                        $head_pic = get_head_pic($users['head_pic']);

                        if ('on' == $img) {

                            $users['html'] = "<img class='{$currentstyle}' alt='{$nickname}' src='{$head_pic}' />";

                        } else {

                            $users['html'] = $nickname;

&nbsp;                       }

                        $users['ey_is_login'] = 1;

                        $this->success('請求成功', null, $users);

       ;             }

                 }

                $this->success('請先(xian)登錄(lu)', null, ['ey_is_login'=>0]);

            }

            else if ('reg' == $type)

            {

    &nbsp;           if (!empty($users_id)) {

                    $users['ey_is_login'] = 1;

                } else {

                    $users['ey_is_login'] = 0;

                }

                $this->success('請求(qiu)成功', null, $users);

            }

            else if ('logout' == $type)

            {

            &nbsp;   if (!empty($users_id)) {

                    $users['ey_is_login'] = 1;

         ;       } else {

                    $users['ey_is_login'] = 0;

      &nbsp;         }

                $this->success('請求成功', null, $users);

            }

            else if ('cart' == $type)

            {

        &nbsp;       if (!empty($users_id)) {

                    $users['ey_is_login'] = 1;

                    $users['ey_cart_num_20191212'] = Db::name('shop_cart')->where(['users_id'=>$users_id])->sum('product_num');

   ;             } else {

                    $users['ey_is_login'] = 0;

                    $users['ey_cart_num_20191212'] = 0;

             ;   }

                $this->success('請(qing)求成功', null, $users);

            }

        }

        $this->error('訪問錯(cuo)誤');

    }

 

下面新(xin)增(zeng)以下代碼(ma):

 

public function check_users()

    {

        if (IS_AJAX) {

            $type = input('param.type/s', 'default');

            $img = input('param.img/s');

            $users_id = session('users_id');

            if ('login' == $type) {

          &nbsp;     if (!empty($users_id)) {

                    $currentstyle = input('param.currentstyle/s');

                    $users = M('users')->field('username,nickname,head_pic')

                         ->where([

                            'users_id'  => $users_id,

                            'lang'      => $this->home_lang,  

             &nbsp;           ])->find();

$head_pic = get_head_pic($users['head_pic']);

&nbsp;                   if (!empty($users)) {

                        $nickname = "<img src='{$head_pic}'>";

                        if (empty($nickname)) {

                            $nickname = $users['username'];

                      &nbsp; }

                        $head_pic = get_head_pic($users['head_pic']);

                        if ('on' == $img) {

                       $users['html'] = "<img class='{$currentstyle}' alt='{$nickname}' src='{$head_pic}' />";

                        } else {

                            $users['html'] = $nickname;

  &nbsp;                     }

                        $users['ey_is_login'] = 1;

                        $this->success('請求成功', null, $users);

    &nbsp;               }

                 }

                $this->success('請先登錄', null, ['ey_is_login'=>0]);

            }

            else if ('reg' == $type)

            {

            &nbsp;   if (!empty($users_id)) {

                    $users['ey_is_login'] = 1;

             ;   } else {

                    $users['ey_is_login'] = 0;

                }

                $this->success('請求(qiu)成(cheng)功', null, $users);

            }

            else if ('logout' == $type)

            {

   ;             if (!empty($users_id)) {

                    $users['ey_is_login'] = 1;

      &nbsp;         } else {

                    $users['ey_is_login'] = 0;

&nbsp;               }

                $this->success('請(qing)求(qiu)成功', null, $users);

            }

            else if ('cart' == $type)

            {

        &nbsp;       if (!empty($users_id)) {

                    $users['ey_is_login'] = 1;

                    $users['ey_cart_num_20191212'] = Db::name('shop_cart')->where(['users_id'=>$users_id])->sum('product_num');

   ;   &nbsp;         } else {

                    $users['ey_is_login'] = 0;

                    $users['ey_cart_num_20191212'] = 0;

           ;     }

                $this->success('請求成功', null, $users);

            }

        }

        $this->error('訪(fang)問錯誤');

    }

保存

 

 

打(da)開:corelibrary hink emplate aglib目錄

 

Eyou.php文件 打(da)開(kai)

 

找到(dao):(89行)

 

'user'       => ['attr' => 'type,id,key,mod,empty,currentstyle,img,txt,txtid'],

 

下(xia)面新(xin)增(zeng)以(yi)下(xia)代(dai)碼:

 

'users'       => ['attr' => 'type,id,key,mod,empty,currentstyle,img,txt,txtid'],

 

再找到以(yi)下代碼(大(da)概2626行(xing))

&nbsp;  public function tagUser($tag, $content)

    {

        $type  =  !empty($tag['type']) ? $tag['type'] : 'default';

        $id     = isset($tag['id']) ? $tag['id'] : 'field';

        $key     = isset($tag['key']) ? $tag['key'] : 'i';

        $txt  =  !empty($tag['txt']) ? $tag['txt'] : '';

&nbsp;       $txt  = $this->varOrvalue($txt);

        $txtid  =  !empty($tag['txtid']) ? $tag['txtid'] : '';

        $img  =  !empty($tag['img']) ? $tag['img'] : 'off';

        $currentstyle   = !empty($tag['currentstyle']) ? $tag['currentstyle'] : '';

 

        $parseStr = '<?php ';

        $parseStr .= ' $tagUser = new hink emplate aglibeyouTagUser;';

        $parseStr .= ' $__LIST__ = $tagUser->getUser("'.$type.'", "'.$img.'", "'.$currentstyle.'", '.$txt.', "'.$txtid.'");';

        $parseStr .= '?>';

 

        $parseStr .= '<?php if(!empty($__LIST__) || (($__LIST__ instanceof hinkCollection || $__LIST__ instanceof hinkPaginator ) && $__LIST__->isEmpty())): ?>';

        $parseStr .= '<?php $'.$id.' = $__LIST__; ?>';

    &nbsp;   $parseStr .= $content;

        $parseStr .= '<?php endif; ?>';

        $parseStr .= '<?php $'.$id.' = []; ?>'; // 清除變量值,只(zhi)限于(yu)在標簽內(nei)部(bu)使(shi)用

 

      &nbsp; if (!empty($parseStr)) {

            return $parseStr;

        }

        return;

    }

在下(xia)面新(xin)增以下(xia)代碼:

 

    public function tagUsers($tag, $content)

    {

        $type  =  !empty($tag['type']) ? $tag['type'] : 'default';

        $id     = isset($tag['id']) ? $tag['id'] : 'field';

        $key     = isset($tag['key']) ? $tag['key'] : 'i';

        $txt  =  !empty($tag['txt']) ? $tag['txt'] : '';

        $txt  = $this-&gt;varOrvalue($txt);

        $txtid  =  !empty($tag['txtid']) ? $tag['txtid'] : '';

        $img  =  !empty($tag['img']) ? $tag['img'] : 'off';

        $currentstyle   = !empty($tag['currentstyle']) ? $tag['currentstyle'] : '';

 

        $parseStr = '<?php ';

        $parseStr .= ' $tagUser = new hink emplate aglibeyouTagUsers;';

        $parseStr .= ' $__LIST__ = $tagUser->getUser("'.$type.'", "'.$img.'", "'.$currentstyle.'", '.$txt.', "'.$txtid.'");';

        $parseStr .= '?>';

 

        $parseStr .= '<?php if(!empty($__LIST__) || (($__LIST__ instanceof hinkCollection || $__LIST__ instanceof hinkPaginator ) && $__LIST__->isEmpty())): ?>';

        $parseStr .= '<?php $'.$id.' = $__LIST__; ?>';

        $parseStr .= $content;

        $parseStr .= '<?php endif; ?>';

        $parseStr .= '<?php $'.$id.' = []; ?>'; // 清除變量(liang)值(zhi),只限于在(zai)標簽內部使用

 

   ;     if (!empty($parseStr)) {

  &nbsp;         return $parseStr;

        }

        return;

    }

 

再打開

corelibrary hink emplate aglibeyou&nbsp;新建一個php文件 

文件名為:

TagUsers.php

 

里面內容為:以下全部(bu)復制進(jin)去:

 

<?php

/**

 * 易優cms

 * ============================================================================

 * 版權(quan)所有 2016-2028 海南(nan)贊贊網絡科技有限(xian)公司(si),并保留(liu)所有權(quan)利(li)。

 * 網站地址: //www.jinyoudianli.com

 * ----------------------------------------------------------------------------

 * 如果商業(ye)用途務必到官方購買正版授權, 以免引起不必要的法律糾紛.

 * ============================================================================

 * Author: 小虎哥 <1105415366@qq.com>

 * Date: 2018-4-3

 */

 

namespace think emplate aglibeyou;

 

use thinkDb;

 

/**

 * 會員中心

 */

class TagUsers extends Base

{

    /**

     * 會員ID

     */

    public $users_id = 0;

 

    //初始化(hua)

    protected function _initialize()

    {

        parent::_initialize();

        // 會員信息

        $this->users_id = session('users_id');

    &nbsp;   $this->users_id = !empty($this->users_id) ? $this->users_id : 0;

    }

 

    /**

     * 會員中心

     * @author wengxianhu by 2018-4-20

     */

    public function getUser($type = 'default', $img = '', $currentstyle = '', $txt = '', $txtid = '')

    {

        $result = false;

 

    &nbsp;   if ($this->home_lang != $this->main_lang) {

          &nbsp; return false;

        }

 

        $web_users_switch = tpCache('web.web_users_switch');

        $users_open_register = getUsersConfigData('users.users_open_register');

 

        if ('open' == $type) {

            if (empty($web_users_switch) || 1 == $users_open_register) {

                return false;

            }

        }

 

  &nbsp;     if (1 == intval($web_users_switch)) {

            if (empty($users_open_register)) {

                $url = '';

                $t_uniqid = '';

&nbsp;               switch ($type) {

                    case 'login':

                    case 'centre':

                    case 'reg':

                    case 'logout':

                    case 'cart':

                        if ('cart' == $type) {

                            $shop_open = getUsersConfigData('shop.shop_open');

&nbsp;                           if (empty($shop_open)) return false; // 關閉商城中心,同(tong)時隱藏購物車(che)入口(kou)

                            $url = url('user/Shop/shop_cart_list');

                        } else if ('reg' == $type) {

                            $users_open_reg = getUsersConfigData('users.users_open_reg');

     ;             &nbsp;         if (isset($users_open_reg) && 1 == $users_open_reg) return false;

                            $url = url('user/Users/'.$type);

                        } else {

                            $url = url('user/Users/'.$type);

&nbsp;                       }&nbsp;

 

  &nbsp;            ;         $t_uniqid = md5(getTime().uniqid(mt_rand(), TRUE));

    &nbsp;                   // A標簽ID

                        $result['id'] = md5("ey_{$type}_{$this->users_id}_{$t_uniqid}");

                        // A標簽里的(de)文案ID

                        $result['txtid'] = !empty($txtid) ? md5($txtid) : md5("ey_{$type}_txt_{$this->users_id}_{$t_uniqid}");

        &nbsp;               // 文字文案

                        $result['txt'] = $txt;

                  &nbsp;     // 購物車的數量ID

                        $result['cartid'] = md5("ey_{$type}_cartid_{$this->users_id}_{$t_uniqid}");

                        // IMG標簽里的ID

                        // $result['imgid'] = md5("ey_{$type}_img_{$this->users_id}_{$t_uniqid}");

                        // 圖片(pian)文案

                        $result['img'] = $img;

             ;           // 鏈(lian)接(jie)

                        $result['url'] = $url;

 ;                       // 標簽類型(xing)

                        $result['type'] = $type;

                         // 圖(tu)片樣式(shi)類

                        $result['currentstyle'] = $currentstyle;

              &nbsp;         break;

 

                    case 'info':

        &nbsp;               $t_uniqid = md5(getTime().uniqid(mt_rand(), TRUE));

                        $result = $this->getUserInfo();

                        foreach ($result as $key => $val) {

                            $html_key = md5($key.'-'.$t_uniqid);

                      &nbsp;  ;   $result[$key] = $html_key;

                    &nbsp;   }

                        $result['t_uniqid'] = $t_uniqid;

                        $result['id'] = $t_uniqid;

              &nbsp;         break;

 

                    case 'open':

            &nbsp;           break;

 

                &nbsp;   default:

            &nbsp;         &nbsp; return false;

              &nbsp;         break;

            &nbsp;   }

 

                if ('login' == $type) {

                    if (isMobile() && isWeixin()) {

                    &nbsp;   // 微信端和小(xiao)程序則使用這個url

                        $result['url'] = url('user/Users/users_select_login');

             ;       }

    &nbsp;           }

 

                // 子目(mu)錄

                $result['root_dir'] = $this->root_dir;

 

  &nbsp;             $result_json = json_encode($result);

      &nbsp;         $version = getCmsVersion();

 

                $hidden = '';

                switch ($type) {

                    case 'login':

                    case 'reg':

                    case 'logout':

                    case 'cart':

  &nbsp;                     $hidden = <<<EOF

 <script type="text/javascript" src="{$this->root_dir}/public/static/common/js/tag_users.js?v={$version}"></script>

<script type="text/javascript">

&nbsp;   var tag_user_result_json = {$result_json};

    tag_user(tag_user_result_json);

</script>

EOF;

                        break;

 

                    case 'info':

                       &nbsp; $hidden = <<<EOF

<script type="text/javascript&quot; src="{$this->root_dir}/public/static/common/js/tag_users.js?v={$version}">;</script>

<script type="text/javascript">

    var tag_user_result_json = {$result_json};

     tag_user_info(tag_user_result_json);

</script>

EOF;

                 ;       break;

      &nbsp;   &nbsp;     }

                $result['hidden'] = $hidden;

            }

        }

 

        return $result;

    }

 

    /**

     * 獲取(qu)用戶信息

     */

    private function getUsersInfo()

    {

        $users = [];

        $tableFields1 = Db::name('users')->getTableFields();

        $tableFields2 = Db::name('users_level')->getTableFields();

        $tableFields = array_merge($tableFields1, $tableFields2);

&nbsp;       foreach ($tableFields as $key => $val) {

            $users[$val] = '';

        }

        $users['url'] = '';

        unset($users['password']);

        unset($users['paypwd']);

 

        return $users;

    }

}

 

最好再(zai)打開publicstaticcommonjs目錄(lu)

新建一個js文件 新建文件名(ming)為:tag_users.js

將以下(xia)內容全部復制進去 保(bao)存:

 

function tag_user(result)

{

    var obj = document.getElementById(result.id);

    var txtObj = document.getElementById(result.txtid);

  &nbsp; var before_display = document.getElementById(result.id).style.display;

    var before_html = '';

    var before_txt_html = '';

    if (txtObj) {

        before_txt_html = txtObj.innerHTML;

        if ('login' == result.type) {

            txtObj.innerHTML = 'Loading&hellip;';

        }

    } else if (obj) {

    &nbsp;   before_html = obj.innerHTML;

        if ('login' == result.type) {

            obj.innerHTML = 'Loading&hellip;';

        }

    }

    if (obj) {

         obj.style.display="none";

    } else {

        obj = txtObj;

    }

    //步驟一:創(chuang)建異步對象

    var ajax = new XMLHttpRequest();

    //步驟二:設(she)置請(qing)求(qiu)的url參(can)(can)(can)數(shu),參(can)(can)(can)數(shu)一是請(qing)求(qiu)的類型,參(can)(can)(can)數(shu)二是請(qing)求(qiu)的url,可(ke)以帶參(can)(can)(can)數(shu),動態的傳(chuan)遞參(can)(can)(can)數(shu)starName到服務端

    var url = result.root_dir+"/index.php?m=api&c=Ajax&a=check_users&type="+result.type+"&img="+result.img;

    if (result.currentstyle != '') {

        url += "&currentstyle="+result.currentstyle;

    }

    ajax.open("post", url, true);

    // 給頭部添(tian)加ajax信(xin)息(xi)

    ajax.setRequestHeader("X-Requested-With","XMLHttpRequest&quot;);

  &nbsp; // 如果需要像 HTML 表單那樣 POST 數據,請使用 setRequestHeader() 來添加 HTTP 頭。然(ran)后在 send() 方法中規定您希望發送的數據:

    ajax.setRequestHeader("Content-type","application/x-www-form-urlencoded");

    //步驟三:發送請求+數據

    ajax.send('_ajax=1');

    //步(bu)驟四:注冊事件(jian) onreadystatechange 狀態(tai)改變就(jiu)會調用

    ajax.onreadystatechange = function () {

        //步驟五 如果能夠進到這個判斷 說(shuo)明(ming) 數據(ju) 完美的(de)回來了,并且請求的(de)頁面是存在的(de)

     ;   if (ajax.readyState==4 && ajax.status==200) {

        &nbsp;   var json = ajax.responseText;  

 ; &nbsp;         var res = JSON.parse(json);

            if (1 == res.code) {

&nbsp; &nbsp;             if (1 == res.data.ey_is_login) {

                   ; if (obj) {

                        if ('login' == result.type) {

                            if (result.txt.length > 0) {

                          &nbsp;     res.data.html = result.txt;

  &nbsp;       &nbsp;                 }

     ;                    ;   if (txtObj) {

      &nbsp;                         txtObj.innerHTML = res.data.html;

                          &nbsp; } else {

                                obj.innerHTML = res.data.html;

              &nbsp;     &nbsp;       }

         &nbsp;                   try {

            &nbsp;                 &nbsp; obj.setAttribute("href", result.url);

  &nbsp;                             if (!before_display) {

                                     obj.style.display=before_display;

                &nbsp;               }

            &nbsp;  ;             }catch(err){}

                        } else if ('logout' == result.type) {

              &nbsp;             if (txtObj) {

                                txtObj.innerHTML = before_txt_html;

  &nbsp;                         } else {

&nbsp;                               obj.innerHTML = before_html;

  &nbsp;                         }

              &nbsp;             try {

                                if (!before_display) {

                              &nbsp;     obj.style.display=before_display;

        &nbsp;                       }

                  &nbsp;         }catch(err){}

                        } else if ('reg' == result.type) {

                            obj.style.display="none";

                        } else if ('cart' == result.type) {

                            try {

                  &nbsp;           &nbsp; var cartidObj = document.getElementById(result.cartid);

                          &nbsp;     if (cartidObj) {

  &nbsp;                                 cartidObj.innerHTML = res.data.ey_cart_num_20191212;

                 ;               }

                                if (!before_display) {

                                &nbsp;   obj.style.display=before_display;

           ;                     }

                    &nbsp;       }catch(err){}

                &nbsp;       }

   ;                 }

&nbsp;             &nbsp; } else {

      &nbsp; &nbsp;           // 恢復未登錄前的(de)html文案

                    if (obj) {

                        if (txtObj) {

                            txtObj.innerHTML = before_txt_html;

        &nbsp;               } else {

             ;               obj.innerHTML = before_html;

          &nbsp;             }

                        if ('logout' == result.type) {

   ;                         obj.style.display="none";

                        } else if ('cart' == result.type) {

                &nbsp;           try {

  &nbsp;                             var cartidObj = document.getElementById(result.cartid);

                   ;         &nbsp;   if (cartidObj) {

            &nbsp;                       cartidObj.innerHTML = res.data.ey_cart_num_20191212;

                                }

          &nbsp;                     if (!before_display) {

                  &nbsp;                 obj.style.display=before_display;

        &nbsp;                       }

                        &nbsp;   }catch(err){}

                         } else {

                            try {

&nbsp;                               if (!before_display) {

                                    obj.style.display=before_display;

&nbsp;                       &nbsp;       }

            &nbsp;               }catch(err){}

                    &nbsp;   }

    &nbsp;               }

    &nbsp;           }

      &nbsp;     } else {

&nbsp;               if (obj) {

                    obj.innerHTML = 'Error';

              &nbsp;     try {

&nbsp;                       if (!before_display) {

              &nbsp;             obj.style.display=before_display;

 &nbsp;                       }

                    }catch(err){}

          &nbsp;     }

            }

       }

    } 

}

 

function tag_user_info(result)

{

    var obj = document.getElementById(result.t_uniqid);

    var before_display = '';

    if (obj) {

      &nbsp; before_display = obj.style.display;

       ; obj.style.display="none";

    }

 

    //步(bu)驟一:創建異(yi)步(bu)對象

    var ajax = new XMLHttpRequest();

    //步驟二:設置請(qing)求的(de)url參(can)數,參(can)數一是(shi)請(qing)求的(de)類型,參(can)數二是(shi)請(qing)求的(de)url,可以帶參(can)數,動態的(de)傳遞參(can)數starName到服務(wu)端

    ajax.open("post", result.root_dir+"/index.php?m=api&c=Ajax&a=get_tag_user_info&t_uniqid="+result.t_uniqid, true);

    // 給頭部(bu)添(tian)加ajax信(xin)息

    ajax.setRequestHeader("X-Requested-With","XMLHttpRequest");

    // 如(ru)果需要像 HTML 表單那樣 POST 數(shu)據(ju),請使用(yong) setRequestHeader() 來添加(jia) HTTP 頭。然后在 send() 方法(fa)中規定您(nin)希望發送(song)的(de)數(shu)據(ju):

    ajax.setRequestHeader(&quot;Content-type","application/x-www-form-urlencoded");

    //步(bu)驟三:發送請(qing)求(qiu)+數據

    ajax.send('_ajax=1');

    //步驟四:注冊事件 onreadystatechange 狀態改變就(jiu)會調用

    ajax.onreadystatechange = function () {

        //步驟(zou)五 如果(guo)能夠(gou)進到這個判斷 說(shuo)明 數據 完美的(de)回(hui)來了(le),并且(qie)請求的(de)頁面是存在的(de)

        if (ajax.readyState==4 && ajax.status==200) {

            var json = ajax.responseText;  

            var res = JSON.parse(json);

            if (1 == res.code) {

              &nbsp; if (1 == res.data.ey_is_login) {

                    var dtypes = res.data.dtypes;

&nbsp;                   var users = res.data.users;

  &nbsp;                 for (var key in users) {

       ;               &nbsp; var subobj = document.getElementById(key);

                        if (subobj) {

                            if ('img' == dtypes[key]) {

          &nbsp;                     subobj.setAttribute("src", users[key]);

                            } else if ('href' == dtypes[key]) {

       ;                         subobj.setAttribute("href", users[key]);

                        &nbsp;   } else {

                &nbsp;               subobj.innerHTML = users[key];

            &nbsp;           &nbsp;   }

          &nbsp;             }

    &nbsp;               }

        &nbsp;           if (obj) {

      &nbsp;                 try {

                         &nbsp;   if (!before_display) {

                   ;             obj.style.display=before_display;

                          &nbsp; }

 ;                       }catch(err){}

              &nbsp;     }

             &nbsp;   } else {

                    if (obj) {

                        obj.style.display="none";

               ;     }

                }

            }

       }

    }

}

 

// 讀(du)取(qu) cookie

function getCookie(c_name)

{

    if (document.cookie.length>0)

    {

      c_start = document.cookie.indexOf(c_name + "=")

      if (c_start!=-1)

      { 

        c_start=c_start + c_name.length+1 

        c_end=document.cookie.indexOf(";",c_start)

     ; &nbsp; if (c_end==-1) c_end=document.cookie.length

            return unescape(document.cookie.substring(c_start,c_end))

      } 

    }

    return "";

}

 

 

到這里教程就(jiu)差不多了(le)。

 

為何要做(zuo)2個user登錄標簽 因為有的模板(ban)只需(xu)(xu)要登錄后顯示單純(chun)頭像,一部分(fen)有的地方還是需(xu)(xu)要顯示昵稱所(suo)以(yi)因需(xu)(xu)所(suo)調用吧。

 

重復說下  以上調用的 標簽為(wei):

 

{eyou:users type='open'}

{eyou:users type='cart'}

        <a href="{$field.url}" id="{$field.id}" >購物車(<font color="red" id="{$field.cartid}">0</font&gt;)</a>

          {$field.hidden}

        {/eyou:users}

{eyou:users type='login'}

<a href="{$field.url}" id="{$field.id}">;登(deng)錄</a> 

{$field.hidden}

{/eyou:users}

{eyou:users type='reg'}

<a href="{$field.url}" id=&quot;{$field.id}">注冊</a> 

{$field.hidden}

{/eyou:users}

{eyou:users type='logout'}

<a href="{$field.url}&quot; id="{$field.id}">退出</a> 

{$field.hidden}

{/eyou:users}

{/eyou:users}

 

不過一般登錄  只(zhi)需

 

{eyou:users type='login'}

<a href="{$field.url}" id="{$field.id}">登(deng)錄(lu)</a> 

{$field.hidden}

{/eyou:users}

 

即可


標簽: 會員登錄

工作日 8:30-12:00 14:30-18:00
周六及部分節假日(ri)提供(gong)值班服務

易小優
轉人工 ×