当前位置:编程学习 > asp >>

如何利用asp实现在一定时间(比如7天)内弹出广告,其它时间不弹出广告

答案:

用cookie。设置一个cookie,有效期为7天,然后读去cookie,第一次因为没有cookie所以弹出,并且设置该cookie,之后7天内都有该cookie所以不弹出,当7天之后cookie过期,又重新弹出并重新设置cookie。

<%
if isNull(Request.Cookies("username")) or Server.HtmlEncode(Request.Cookies("ad").Value)<>"start" then
Response.Cookies("ad").Value="start";
Response.Cookies("ad").Expires=DateTime.Now.AddDays(7);
else
  Call 弹广告
end if
%>


[page_break]

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>index</title>
</head>
<%
mydate="10/23/2006"
mydate=dateadd("d",10,mydate)
if DATEDIFF("d",DATE,mydate) > 0 Then
%>
<script language="javascript">
    window.open('http://cn58.net‘)
</script>
<%
Else
response.write "no"
end If
%>
<body>
</body>
</html>

上一个:两段代码防止一般的采集以及小偷读取,加在顶部
下一个:编写通用的ASP防SQL注入攻击程序

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,