几组实用的ASP程序和JS脚本代码
  • 首页 > 电脑网络
  • 作者: Joseffu
  • 2005年9月25日 8:40 星期日
  • 浏览:4044 次
  • 字号:   
  • 评论:0 条  
  • 时间:2005-9-25 8:40   浏览:4044  

    ASP与Access数据库连接:

    <%@ language=VBscript%> 
    <% 
    dim conn,mdbfile 
    mdbfile=server.mappath("数据库名称.mdb") 
    set conn=server.createobject("adodb.connection") 
    conn.open "driver={microsoft access driver (*.mdb)};uid=admin;pwd=数据库密码;dbq="&mdbfile 
    %>

    基本的分页代码:

    <%
    Response.write "<b>>> 全部 - "
    Response.write "共</font> " & "<font color=#FF0000>" & Cstr(Rs.RecordCount) & "</font>" & " 条信息</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
    Response.write "<b>第&nbsp;" & "<font color=#FF0000>" & Cstr(CurrentPage) &  "</font>" & "/" & Cstr(rs.pagecount) & "</b>&nbsp;&nbsp;&nbsp;&nbsp;"
    If currentpage > 1 Then
    response.write "<b><a href='?&page="+cstr(1)+"'>首页</a></b>&nbsp;&nbsp;"
    Response.write "<b><a href='?page="+Cstr(currentpage-1)+"'>上一页</a></b>&nbsp;&nbsp;"
    Else
    Response.write "<b>上一页</b>&nbsp;&nbsp;"
    End if
    If currentpage < Rs.PageCount Then
    Response.write "<b><a href='?page="+Cstr(currentPage+1)+"'>下一页</a>&nbsp;&nbsp;"
    Response.write "<a href='?page="+Cstr(Rs.PageCount)+"'>尾页</a></b>&nbsp;&nbsp;"
    Else
    Response.write ""
    Response.write "<b>下一页</b>&nbsp;&nbsp;"
    End if
    %>

    简单的ASP程序密码锁,即浏览需身份验证的页面:

    使用ASP程序来给网页进行加密,一般来说利用程序来进行密码验证的方法比较通用,现在大多数网站都使用ASP程序,它对Web服务器没有具体要求,而其加密就是借助数据库及ASP程序进行设计,来实现一种通用网页加密。

    1. 打开 Microsoft Access,建立一个“用户名及密码”的数据表,假设将这个表取名为User,数据库名为db.mdb

    数据表的结构如下:

    字段说明 字段名称 数据类型 数据长度

    用户名称   ID     文本   15

    用户密码   PWD   文本   15

    2. 编辑一个 Pass.asp 的验证文件,源代码如下:

    <%
    Function Check( ID, Pwd )
    Dim conn, par, rs
    Set conn = Server.CreateObject("ADODB.Connection")
    par = "driver={Microsoft Access Driver (*.mdb)} "
    conn.Open par && ";dbq=" && Server.MapPath("db.mdb ")
    sql = "Select ? From users Where ID='" && ID && "' And Pwd = '" && Pwd &&"'"
    Set rs = conn.Execute( sql )
    If rs.EOF Then
    Check= False
    Else
    Check= True
    End If
    End Function
    %>
    <%
    If IsEmpty(Session("Passed")) Then Session("Passed") = False
    Head = "请输入用户名和密码"
    ID = Request("ID")
    Pwd = Request("Pwd")
    If ID = "" Or Pwd = "" Then
    Head = "请输入用户名和密码"
    Else If Not Check( ID, Pwd ) Then
    Head = "用户名称或密码有错"
    Else
    Session("Passed") = True
    End If
    If Not Session("Passed") Then
    %>
    <html>
    <head>
          <title></title>
          </head> 
    <body BGCOLOR="#FFFFFF">
    <h2 ALIGN="CENTER"><%=Head%></h2>
    <hr WIDTH="100%">
    <form Action="<%=Request.ServerVariables("PATH_INFO")%>" Method="POST">
    <table BORDER="1" CELLSPACING="0">
    <tr>
    <td ALIGN="RIGHT">用户名称:</td>
    <td><input Type="Text" Name="ID" Size="12" Value="<%=ID%>"></td>
    </tr>
    <tr> <td ALIGN="RIGHT">密码:</td>
    <td><input Type="Password" Name="Pwd" Size="12" Value="<%=Pwd%>"></td></tr>
    </table>
    <p><input Type="Submit" Value="确定"></p></form>
    <hr WIDTH="100%" align="center">
    </body>
          </html>
    <%Response.End
    End If %>

    3. 在需要加密网页的HTML代码最前面加上 <! --#include file="pass.asp"--> 就可以了。由于这个验证合法性的页面具有通用性,所以非常方便使用。

    禁止复制和右键菜单的脚本及代码:

    1、

    <body oncontextmenu='return false' ondragstart='return false' onselectstart ='return false' onselect='document.selection.empty()' oncopy='document.selection.empty()' onbeforecopy='return false' onmouseup='document.selection.empty()'>

    2、

    <body oncontextmenu="return false" ondragstart="return false" onselectstart ="return false" onselect="document.selection.empty()" oncopy="document.selection.empty()" onbeforecopy="return false">

    3、

    <script type="text/javascript">
    document.body.oncut=function(){return false;};
    document.body.onselectstart=function(){return false;};
    var printBody=document.getElementById("printBody");
    if (printBody!=undefined){
      printBody.oncopy=function(){return false;};
    }
    </script>

    4、

    <body oncontextmenu="return false" ondragstart="return false" onselectstart="return false" onMouseOver="window.status='状态栏';return true">

    5、

    <body oncontextmenu="return false" onselectstart ="return false">

    最简单的是第五种,最原始的代码就是:oncontextmenu="return false" 禁右键,onselectstart ="return false" 禁选中,用在<body>属性里,以前一直挺管用的,包括现在放IE里浏览也很灵,但随着整合了各种插件的第三方功能强劲的浏览器的出现,常常可以轻松破除、破解各种IE浏览器中的局限性和限制。这类禁止鼠标左右键的小儿科碰上EnableRightClick这插件就完蛋。归根结底是防菜鸟和懒人的,真的要破除限制,即使没有插件帮忙,一样能搞定。其它的几个增加了一些额外的参数,如第四个加入了状态栏信息。 第三个不同于其它四个(算是嵌入HTML代码),是加入的脚本,还有以前那些击右键就弹出收藏夹或是“禁止复制”的提示,现在来看都是弱智型的了。

    浮动的图片层,位置固定的:

    <SCRIPT> 
    var sgImg="图片URL"
    var sgWidth=63
    var sgHeight=300
    var sgLink="链接URL"
    var sgNS=(document.layers)?true:false
    if(sgNS){document.write('<LAYER ID="Corner" WIDTH='+sgWidth+' HEIGHT='+sgHeight+'><A href="'+sgLink+'" target=_blank><IMG src="'+sgImg+'" BORDER=0 WIDTH="'+sgWidth+'" HEIGHT="'+sgHeight+'"></A></LAYER>');}else{document.write('<DIV ID="Corner" STYLE="position:absolute; width:'+sgWidth+'; height:'+sgHeight+'; z-index:9; filter: Alpha(Opacity=70)"><A href="'+sgLink+'" target=_blank><IMG src="'+sgImg+'" BORDER=0 WIDTH="'+sgWidth+'" HEIGHT="'+sgHeight+'"></A></DIV>');}
    function StayCorner(){var sgTop;var sgLeft
    if(sgNS){sgTop  = pageYOffset+window.innerHeight-document.Corner.document.height-10;sgLeft = pageXOffset+window.innerWidth-document.Corner.document.width-10;document.Corner.top  = sgTop;document.Corner.left = sgLeft;}else{
    sgTop  = document.body.scrollTop+document.body.clientHeight-document.all.Corner.offsetHeight-30;sgLeft = document.body.scrollLeft+document.body.clientWidth-document.all.Corner.offsetWidth-5;Corner.style.top  = sgTop;Corner.style.left = sgLeft;}
    setTimeout('StayCorner()', 50)}
    sgDump = StayCorner()
    </SCRIPT>

    返回上一步

    以下两种都可以:

    <a href=javascript:history.back()>返回</a>
    <a href=javascript:history.go(-1)>返回</a>

    额外参数(ASP):返回上一步时强制浏览器重新访问服务器下载页面,非从缓存读取页面,实际上等于返回到上一步再刷新一次,以确保页面信息的时效性:

    <%
    Response.Buffer = True 
    Response.Expires = 1000
    Response.ExpiresAbsolute = Now() - 1 
    Response.Expires = 0 
    Response.CacheControl = "no-cache" 
    %>

    去掉点击图片链接后图片周围的虚线:

    1、调用方式:

    <public:attach event="onfocus" onevent="example()" />
    <script language="javascript">
    function example(){
    this.blur();
    }
    </script>

    //将以上代码存为以.htc为扩展名的文件,然后再编写一个普通的HTML页。

    <html>
    <head>
    <style>
    A {behavior:url(HTC文件所在的路径地址,完整URL)}
    </style>
    <body>网页内容……
    </body>
    </html>

    2、单独的图片文件:

    图片属性里的语法为:onFocus="this.blur()" ,比如:

    <a href="http://joseffu.gorgor.org/admin.php#" onFocus="this.blur()"><img src="图片URL" border=0></a>

    禁止提示脚本的错误信息的小脚本:

    <SCRIPT LANGUAGE="javascript"> 
    <!-- Hide 
    function killErrors() { 
    return true; 
    } 
    window.onerror = killErrors; 
    // --> 
    </SCRIPT>

    页面上脚本语法搞错,有错误提示,却又搞不定,而页面功能无碍的情况下,可以这样偷个懒,把错误提示隐藏掉。

  • 本文没有标签
    昵称  邮箱  主页 
    表情1 表情2 表情3 表情4 表情5 表情6 表情7 表情8 表情9 表情10 表情11 表情12 表情13 表情14 表情15 表情16 表情17 表情18 表情19 表情20 表情21
    30 + 27 =
    Copyright © 2004-2024  Joseffu Online 博客首页 鲁ICP备2021023008号-1 繁体中文
  • 日志:296 篇
  • 评论:226 条
  • 微语:25 条
  • 友链:18 个
  • 分类:5 个
  • 标签:29 个
  • 建站:2004-11-22

    已运行