主题:  关于阅读权限控制的另一种思路求解

xtbr

职务:普通成员
等级:1
金币:0.0
发贴:20
#12005/7/12 7:30:59
我下了一个程序修改,它原来的阅读控制是新闻有0-3个级别,对应用于中的游客,普通会员,高级,特级会员。
news表中有newslevel字段(0,1,2,3) 用户表user中有reglevel字段(1,2,3)

<%if Request.cookies(Forcast_SN)("key"="selfreg" then
if cINT(Request.cookies(Forcast_SN)("reglevel")>=cINT(wzdj) then%> <%Response.Write arr_Content(Page-1)%>
<% else %>
'selfreg为注册用户
'wzdj是取自news表中有newslevel字段
<%Response.Write arr_Content(Page-1)%> 正常浏览


这样的方式不能完成更多的权限分配,我做了一下修改,news表中有newslevel字段取值可以是0,1,2,3,4....9范围内的任意一个值。用户表中加了一个readlevel. readlevel的值以|分隔,例如A用户的realevel值是 2|5|8|9 ,A用户就可以阅读newslevel为2,5,8,9任意一值的文章.

我自己改了一下
<%
        Set rsh = Server.CreateObject("ADODB.Recordset"
        sqlh ="select * from "& db_User_Table &" order by ID"
        RSh.open sqlh,Conn,3,3
        %>


<%
        do while not rsh.eof
            dim readlevel,level1,level2
            level2=rsh("readlevel"
            if level2<>"" then
                level1=split(level2,"|"
                for i=0 to ubound(level1)
                    if cstr(wzdj)=trim(level1(i)) then
                        readlevel=true
                        Response.Write arr_Content(Page-1) '正常阅读
                        exit for
                    else
                        readlevel=false
                        Response.write "权限值不匹配,无法阅读"
                    end if
                next
            end if
            %>
    
        
        <%
    RSh.MoveNext
        Loop
        rsh.close
        set rsh=nothing
        %>
我参考过,http://www.blueidea.com/bbs/newsdetail.asp?id=1182446&posts=current
运行的时候,什么用户都能看,结果也重复显示很多次。
因为刚用asp做网页,很多代码的地方,都找不到案例学习,这个地方我已经改了很多次就是改不出来。大家帮我一下吧。



xtbr

职务:普通成员
等级:1
金币:0.0
发贴:20
#22005/7/12 7:31:37
这是原来的网页
<!--#include file="conn.asp"-->
<!--#include file="ConnUser.asp"-->
<!--#include file="config.asp"-->
<!--include file="char.inc"-->
<!--#include file="function.asp"-->
<%
IF request.cookies(Forcast_SN)("KEY"="" THEN
else
    usernamecookie=CheckStr(request.cookies(Forcast_SN)("UserName")
    passwdcookie=CheckStr(trim(Request.cookies(Forcast_SN)("passwd"))
    KEYcookie=CheckStr(trim(request.cookies(Forcast_SN)("KEY"))
    if usernamecookie="" or passwdcookie="" then
        response.cookies(Forcast_SN)("UserName"=""
        response.cookies(Forcast_SN)("KEY"=""
        response.cookies(Forcast_SN)("purview"=""
        response.cookies(Forcast_SN)("fullname"=""
        response.cookies(Forcast_SN)("reglevel"=""
    else
        '判断用户的合法性
        set rs=server.createobject("adodb.recordset"
        sql="select * from "& db_User_Table &" where "& db_User_Name &"='"&usernamecookie&"'"
        rs.open sql,ConnUser,1,1
        if rs.eof and rs.bof then
            response.cookies(Forcast_SN)("UserName"=""
            response.cookies(Forcast_SN)("KEY"=""
            response.cookies(Forcast_SN)("purview"=""
            response.cookies(Forcast_SN)("fullname"=""
            response.cookies(Forcast_SN)("reglevel"=""
        end if
        IF passwdcookie<>rs(db_User_Password) THEN
            response.cookies(Forcast_SN)("UserName"=""
            response.cookies(Forcast_SN)("KEY"=""
            response.cookies(Forcast_SN)("purview"=""
            response.cookies(Forcast_SN)("fullname"=""
            response.cookies(Forcast_SN)("reglevel"=""
        END IF
        '下面判断用户级别实际在有用户级别是都应该判断
        if KEYcookie<>rs("OSKEY" then
            response.cookies(Forcast_SN)("UserName"=""
            response.cookies(Forcast_SN)("KEY"=""
            response.cookies(Forcast_SN)("purview"=""
            response.cookies(Forcast_SN)("fullname"=""
            response.cookies(Forcast_SN)("reglevel"=""
        end if
        rs.close
        set rs=nothing
    END IF
END IF

'该文件需要进行调整和设置
dim typename
NewsID=Request.QueryString("NewsID"
Page=Request.QueryString("page"

if page="" then
    page=1
    elseif not IsNumeric(page) then
        Show_Err("非法参数!<br><br><a href='javascript:history.back()'>返回</a>"
        response.end
    end if
    page=int(page)
    if newsid="" then
        Show_Err("未指定参数!<br><br><a href='javascript:history.back()'>返回</a>"
        response.end
    elseif not IsNumeric(newsid) then
        Show_Err("非法参数!<br><br><a href='javascript:history.back()'>返回</a>"
        response.end
    else
        '判断该篇文章是否审核
        set rs=server.createobject("adodb.recordset"
        sql="select * from "& db_News_Table &" where NewsId="&NewsId
        rs.open sql,conn,3,3
        if rs.eof and rs.bof then
            rs.close
            set rs=nothing
            Show_Err("指定的文章不存在!<br><br><a href='javascript:history.back()'>返回</a>"
            response.end
        else
            checked=rs("checkked"
            if checked=1 or Request.cookies(Forcast_SN)("key"="super" or Request.cookies(Forcast_SN)("key"="typemaster" or Request.cookies

(Forcast_SN)("key"="bigmaster" or Request.cookies(Forcast_SN)("key"="smallmaster" then    
                Click=rs("Click"
                if isnull(rs("Click") then
                    conn.execute("update "& db_News_Table &" Set Click=1 where NewsID=" & NewsID )
                else
                    conn.execute("update "& db_News_Table &" Set Click=click+1 where NewsID=" & NewsID )
                end if
            end if
            rs.close
            set rs=nothing
        end if

        set rs=server.CreateObject("ADODB.RecordSet"
        if uselevel=1 then
            if Request.cookies(Forcast_SN)("key"="" then
                rs.Source="select * from "& db_News_Table &" where checkked=1 and newslevel=0 and newsid="&newsid
            end if
            if Request.cookies(Forcast_SN)("key"="selfreg" then
                if Request.cookies(Forcast_SN)("reglevel"=3 then
                    rs.Source="select * from "& db_News_Table &" where checkked=1 and newslevel<=3 and newsid="&newsid
                end if
                if Request.cookies(Forcast_SN)("reglevel"=2 then
                    rs.Source="select * from "& db_News_Table &" where checkked=1 and newslevel<=2 and newsid="&newsid
                end if
                if Request.cookies(Forcast_SN)("reglevel"=1 then
                    rs.Source="select * from "& db_News_Table &" where checkked=1 and newslevel<=1 and newsid="&newsid
                end if
            end if
        end if
            if Request.cookies(Forcast_SN)("key"="super" or Request.cookies(Forcast_SN)("key"="typemaster" or Request.cookies(Forcast_SN)

("key"="bigmaster" or Request.cookies(Forcast_SN)("key"="smallmaster" or Request.cookies(Forcast_SN)("key"="check" then
                rs.Source="select * from "& db_News_Table &" where newsid="&newsid
            else
                rs.Source="select * from "& db_News_Table &" where newsid="&newsid
            end if
            rs.Open rs.Source,conn,1,1
            bigclassid=rs("bigclassid"
            smallclassid=rs("smallclassid"
            title=htmlencode4(trim(rs("title"))
            title1=htmlencode4(trim(rs("title"))
            about=htmlencode4(trim(rs("about"))
            Author=htmlencode4(trim(rs("Author"))
            editor=htmlencode4(trim(rs("editor"))
            Original=htmlencode4(trim(rs("Original"))
            image=rs("image"
            UpdateTime=trim(rs("UpdateTime")
            datatime=trim(rs("datatime")
            News_Content=rs("Content"
            SpecialID=rs("SpecialID"
            SpecialID2=rs("SpecialID2"
            click=rs("click"
            EnCode=trim(rs("EnCode")
            typeid=rs("typeid"
            titletype=rs("titletype"
            titlecolor=rs("titlecolor"
            titleface=rs("titleface"
            editor=rs("editor"
            wzdj=rs("newslevel"
            backtype=rs("backtype"
            rs.Close
            set rs=nothing

            set rs=server.CreateObject("ADODB.RecordSet"
            rs.Source="select * from "& db_Type_Table &" where typeID=" & typeID
            rs.Open rs.Source,conn,1,1
            typename=rs("typename"
            rs.Close
            set rs=nothing
            set rs=server.CreateObject("ADODB.RecordSet"
            rs.Source="select * from "& db_BigClass_Table &" Where BigClassid=" & BigClassid
            rs.Open rs.Source,conn,1,1
            bigclassname=rs("bigclassname"
            rs.close
            set rs=nothing
            if smallclassid<>"" then
                set rs=server.CreateObject("ADODB.RecordSet"
                rs.Source="select * from "& db_SmallClass_Table &" Where smallClassid=" & smallClassid
                rs.Open rs.Source,conn,1,1
                smallclassname=rs("smallclassname"
                rs.close
                set rs=nothing
            end if%>
<html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>内容页</title>
<style type="text/css">
.newstitle {COLOR: #000000; FONT-FAMILY:"Verdana, Arial, 宋体"; FONT-SIZE: 14px;line-height:1.5}
.style2 {color: #cc0000}
</style>
</head>
<body marginheight="0">
<!--#include file="top.asp"-->
<table width="901" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
    <tr valign="top">
        <td>
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                 <td valign="top">
                        <table width="102%" border="0" cellspacing="0" cellpadding="0">
                            <tr bgcolor="#FFFFFF">
                             <td width="100%" height="25" background="skins/wm/52design_img007.gif" bgcolor="#FFFF99" >当前位置:首页-
                             <%=typename%><%if bigclassid<>"" then%><%=BigClassName%><%if smallclassid<>"" then%><%=SmallClassName%><%end if%><%end if%>
<%title1=htmlencode4(title1)%>
                             </td>
                            </tr>
                            <tr bgcolor="#FFFFFF">
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td valign="top">&nbsp; </td>
                </tr>
            </table>
        </td>
    </tr>
    <tr valign="top">
        <td>
            <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
                <tr>
                <td width="18">&nbsp;</td>
                 <td width="692" valign="top"><table width="98%" border="0" align="center" cellpadding="0" cellspacing="0"

bgcolor="#FFFFFF">
<tr>
<td width="100%" height="54" align=center valign="middle"> <table width="100%" height="6"

border="0" cellpadding="0" cellspacing="0">
<tr>
<td></td>
</tr>
</table>
<font color="red" size="+2" face="黑体"><%=title1%></font>
<table width="100%" height="6" border="0" cellpadding="0" cellspacing="0" class="ho1">
<tr>
<td></td>
</tr>
</table>
<br>
<%if datatime<>"" then%>【信息时间】:<%=year(datatime)%>-<%=month(datatime)%>-<%=day(datatime)%><%end if%>&nbsp;【发布日期】:<%=year(updateTime)%>-<%=month(updateTime)%>-<%=day(updateTime)%>&nbsp;
<%if Original<>"" then%>【来源】:<%=Original%><%end if%><%if Author<>"" then%>【作者】:<%=Author%><%end if%>
&nbsp;【发布人:<a href="User.asp?user=<%=editor%>"><%=editor%></a>】
</td>
</tr>
<%
set rs=server.CreateObject("ADODB.RecordSet"
rs.Source="select * from "& db_News_Table &" where NewsID=" & NewsID
rs.Open rs.source,conn,1,1
typeid=rs("typeid"
Title=trim(rs("Title")
image=rs("image"

dim mode

set rs11=server.CreateObject("ADODB.RecordSet"
rs11.Source="select * from "& db_Type_Table &" where typeid="&typeid&" order by typeid"
rs11.Open rs11.Source,conn,1,1
mode=rs11("mode"
rs11.close
set rs11=nothing

''添加图片鼠标滚轮缩放效果
if mouse_wheel_zoom="on" then
    News_Content=replace(News_Content,"<IMG","<IMG onmousewheel='return img_zoom(event,this)' onload='javascript:if(this.width>screen.width-333)

this.width=screen.width-333'",1,-1,1)
end if
''图片上传路径还原为 config.asp 中设定的 [FileUploadPath] 值
News_Content=replace(News_Content,"="&chr(34)&"uploadfile/","="&chr(34)&FileUploadPath,1,-1,1)

arr_Content=split(News_Content,"[---分页---]"
MaxPages=ubound(arr_Content)
%>
<tr>
<td width="100%" height="420" align="center" valign="top">
                            
<table border="0" cellspacing="0" cellpadding="0" align="center" style="overflow-x:scroll; width:650;">
<tr>
<td width="100%" align=center></td>
</tr>
<tr>
<TD class=newstitle id=fontzoom vAlign=top>
                                 <div style="overflow-x:auto; width:650;">
<%if M_BG=1 and rs("picnews"=0 and Not Instr(rs("Content","TD">0 then%>
<table border=0 align="left" cellpadding=3>
<tr>
<td>
</td>
</tr>
</table>
<%end if%>
<%if (checked<>1) and ((Request.cookies(Forcast_SN)("key"<>"super" and (Request.cookies(Forcast_SN)("key"

<>"typemaster" and (Request.cookies(Forcast_SN)("key"<>"bigmaster" and (Request.cookies(Forcast_SN)("key"<>"smallmaster") then    '文章未审核,并且是非

相关管理员
    response.write "<P><CENTER><strong><font color='0000ff' size='+2' face='隶书'>文章还未经过审核<br>请等待或者通知管理员审核才能阅览!

</font></strong></CENTER>"
    response.write "<P>"
else    '文章已审核
    if checked<>1 then
        response.write "<P><CENTER><strong><font color='ff00ff' size='+2' face='隶书'>提醒:该文章还未通过审核</font></strong></CENTER>"
    end if

if uselevel=1 then

    if cINT(wzdj)<1 then
        Response.Write arr_Content(Page-1)%>
<% else %>
<%if Request.cookies(Forcast_SN)("key"="super" or Request.cookies(Forcast_SN)("key"="typemaster" or Request.cookies

(Forcast_SN)("key"="bigmaster" or Request.cookies(Forcast_SN)("key"="smallmaster" or Request.cookies(Forcast_SN)("key"="check" then %>
<%Response.Write arr_Content(Page-1)%>
<% else %>
<%if Request.cookies(Forcast_SN)("key"="" then%>
<br>
<font color="#cc0000"><b>内容简介:</b></font><br>
<br>
<%=CutStr(nohtml(rs("Content"),150)%>... <br>
<br>
<br>
<font color="#cc0000"><b>友情提醒:</b></font><br>
<br>
这篇信息要求是符合权限要求的用户才能阅读,您的<span class="style2">浏览权限不够</span>或<span class="style2">未登陆</span> !<br>
<br>
<%
                response.write "文章级别:"
                response.write cINT(wzdj)
                response.write "级"
                %>
<br>
<%
                response.write "您现在的个人状态:"
                response.write "无权限或未登陆"
                %>
<% else %>
<%if Request.cookies(Forcast_SN)("key"="selfreg" then
                    if cINT(Request.cookies(Forcast_SN)("reglevel")>=cINT(wzdj) then%>
<%Response.Write arr_Content(Page-1)%>
<% else %>
<br>
<font color="#cc0000"><b>内容简介:</b></font> <br>
<br>
<%=CutStr(nohtml(rs("Content"),150)%>... <br>
<br>
<br>
<font color="#cc0000"><b>友情提醒:</b></font><br>
<br>
<br>
这篇信息要求符合权限要求的用户才能阅读,您的<span class="style2">浏览权限不够</span>或<span class="style2">未登陆</span> !<br>
<br>
<%
                        response.write "文章级别:"
                        response.write cINT(wzdj)
                        response.write "级"
                        %>
<br>
<%
                        response.write "您的权限:"
                        response.write (Request.cookies(Forcast_SN)("reglevel")
                        response.write "级"
                        %>
<br>
<br>
<br>
<br>
<%end if%>
<%end if%>
<%end if%>
<%end if%>
<%end if%>
<%else%>
<%Response.Write arr_Content(Page-1)%>
<%end if%>
<%end if%>
<br>

<%
url="datum.asp?NewsId="&newsid
if MaxPages >0 then
    Response.write "<a class=black href='"& Url &"&page=1' title='第1页'>首页</a> "
    if Page-1 > 0 then
        Prev_Page = Page - 1
        Response.write "<a class=black href='"& Url &"&page="& Prev_Page &"' title='第"& Prev_Page &"页'>上一页</a> "
    end if

    for PageCounter=0 to MaxPages
        PageLink = PageCounter+1
        if PageLink <> Page Then
            Response.write "<a class=black href='"& Url &"&page="& PageLink &"'>["& PageLink &"]</a> "
        else
            Response.Write "<font color='#FF0000'><B>["& PageLink &"]</B></font> "
        end if
        If PageLink = MaxPages+1 Then Exit for
    Next
    if page <= Maxpages then
        bdd_Page = Page + 1
        Response.write "<a class=black href='" & Url & "&page=" & bdd_Page & "' title='第" & bdd_Page & "页'>下一页</A>"
    end if
    Response.write " <A class=black href='" & Url & "&page=" & Maxpages+1 & "' title='第"& Maxpages+1 &"页'>尾页</A>"
end if
%>
</div> </td>
</tr>
</table> </td>
</tr>
<tr>
<td width="100%" height="25"><div align="center">
<!--#include file=attach.asp -->
</div></td>
</tr>
</table></td>
                </tr>
         </table>
     </td>
    </tr>
</table>

<!--#include file=bottom.asp -->
</body>
</html>
    <%end if%>
<%
conn.close
set conn=nothing
%>



{ 在指尖上绽放的花朵 }

职务:普通成员
等级:5
金币:14.0
发贴:3209
#32005/7/12 18:16:01
readlevel 设定为一个数字不可以?

用户只可以读小于 readlevel 级别的东西。。。。