js
var name = "Ins_sms"; var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)"); arr = document.cookie.match(reg) if (arr == null) { msgHide("请先获取验证码!"); return false; } if (yzm != unescape(arr[2])) { msgHide("错误的验证码!"); return false; }
C#
if (context.Request.Cookies["Ins_sms"] == null) { //context.Request.Cookies["Ins_sms"].Value = "123"; //context.Request.Cookies["Ins_sms"].Expires = DateTime.Now.AddSeconds(60); DALVibeApi dal = new DALVibeApi(); Random rd = new Random(); string num = rd.Next(9999).ToString().PadLeft(4,'0'); string result = dal.SMS(phone, num); if (result == "0000") { HttpCookie cookie = new HttpCookie("Ins_sms"); //设置cookies到期时间 cookie.Value = num; cookie.Expires = DateTime.Now.AddSeconds(60); context.Response.Cookies.Add(cookie); context.Response.Write("success"); } else { context.Response.Write("fail"); } } else { context.Response.Write("fail"); }