织梦限制某些内容只有登录可以查看

传递参数加SQL实现,具体方法如下:

1、在内容页head之间加上JS:

<script src=https://www.91084.com/"{dede:global.cfg_cmsurl/}/include/dedeajax2.js" type="text/javascript" ></script>

<script language="javascript">

function CheckLogin_c(){

 var taget_obj = document.getElementById('_userlogin_c');

 var req = document.getElementById('hid').value;

 myajax = new DedeAjax(taget_obj,false,false,'','','');

myajax.SendGet2("{dede:global.cfg_cmspath/}/member/ajax_loginsta_c.php?val="+req);

 DedeXHTTP = null;

}

</script>

2、在内容页需要会员限制才能查看的地方添加代码(会员登录前的样子):

<span id="_userlogin_c"><a href=https://www.91084.com/"/member/index_do.php?fmdo=user&dopost=regnew">请注册后查看!</a></span>

<input type="hidden" value="{dede:field.aid/}" id="hid" />

<script language="javascript" type="text/javascript">CheckLogin_c();</script>

这里获取文章ID的文本框一定要在js之前

3、在/member文件夹中新建一个文件:ajax_loginsta_c.php,添加如下代码(会员登录后的样子):

<?php

require_once(dirname(__FILE__)."/config.php");

AjaxHead();

if($myurl == '')

{

 exit('');

}

$uid  = $cfg_ml->M_LoginID;

!$cfg_ml->fields['face'] && $face = ($cfg_ml->fields['sex'] == '女')? 'dfgirl' : 'dfboy';

$facepic = empty($face)? $cfg_ml->fields['face'] : $GLOBALS['cfg_memberurl'].'/templets/images/'.$face.'.png';

?>

<?php

$row = $dsql->GetOne(" Select * From `js_addoninfos` where `aid`=$val ");

?>

<?php echo $row['tel']; ?>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wsfzgf.html