>  기사  >  웹 프론트엔드  >  JQuery 및 s3captche를 사용하여 과일 name_jquery 확인 구현

JQuery 및 s3captche를 사용하여 과일 name_jquery 확인 구현

WBOY
WBOY원래의
2016-05-16 18:48:111017검색

먼저 사진을 보세요:

1. 소개:

s3captcha는 이미지를 순차적으로 표시할 수 있는 매우 유용한 JQuery 플러그인입니다. php를 통해 구현됩니다. 하지만 이를 asp.net 및 C# 코드로 변환하는 것이 쉽다는 것을 알았습니다. 이미지의 소스와 이름을 구성할 수 있는 구성 구성 파일을 만들었습니다.

그럼 s3captcha의 구현 원리를 소개하자면,

위 그림은 구현 모드를 보여줍니다.
1. 이미지의 인덱스를 즉시 생성합니다.
2. 이미지의 인덱스에 일련의 임의의 데이터를 할당합니다.
3. >4. 그림을 라디오 상자로 무작위로 표시합니다.
JQuery를 사용하여 라디오 상자를 그림 목록으로 변환합니다.
2. 코드:
먼저 이미지 인덱스 배열 순서를 어지럽히고 다시 출력합니다:

코드 복사 코드는 다음과 같습니다.
public static List shuffle(List input)
{
List 출력 = new List() ;
Random rnd = new Random();

int FIndex
while (input.Count > 0)
{
FIndex = rnd.Next(0, input. 개수);
output.Add(input[FIndex]);
input.RemoveAt(FIndex)

input.Clear(); 🎜>rnd = null;

return 출력;
}


xml을 s3captche 구성 파일로 사용:



코드 복사 사과,체리,레몬,배,딸기사과,체리,레몬,배,딸기> <div class="codebody" id="code90994"><너비>33</너비> <br><높이>33</높이> <br><ext>jpg</ext> ></icons> <br><message>로봇이 아닌 인간인지 확인하세요. {0}</message> <br></s3capcha><br><br><br>GetHtmlCode를 선택하세요. 코드: <br> <br><br><br><br>코드 복사<br> </div> <br> 코드는 다음과 같습니다.<br><div class="codetitle"> <span>public static string GetHtmlCodes(string PathTo , out int SessionValue) <a style="CURSOR: pointer" data="68968" class="copybut" id="copybut68968" onclick="doCopy('code68968')"> { <u>bool HasValue = false </u>if (string.IsNullOrEmpty(Message)) </a>HasValue = LoadConfig() </span>else </div>HasValue = true; 🎜><div class="codebody" id="code68968">if (HasValue ) <br>{ <br>Random Rnd = new Random(); <br>int RandomIndex = Rnd.Next(0,IconNames.Length) <br><br>List<int> ; 값 ​​= 새로운 List<int> <br>for(int i = 0; i < IconNames.Length;i ) <BR>values.Add(i) ​​= shuffle (값); <br><br>string WriteThis = "<div class="s3capcha"><p>" <br>string.Format(Message, "<strong>" IconTitles[values[RandomIndex] ] <br>"</strong>") "</p>" <br><br>int[] RandomValues ​​​​= new int[IconNames.Length] <br>for (int i = 0 ; i < IconNames.Length; i ) <BR>{ <BR>Rnd.Next() <BR>WriteThis = string.Format(RowTemplate, <br>IconTitles[i]] RandomValues[i], <br>PathTo "/icons/" 폴더 "/" <BR>IconNames[values[i]] "." 확장자, <BR>너비, 높이) <br>} <br>WriteThis = "<div "clear :left"></div></div>"; <br>SessionValue = RandomValues[RandomIndex] <br>return WriteThis; } <br>else <br>{ <br>SessionValue = -1; <br>return "잘못된 데이터, 구성 파일을 찾을 수 없음" <br>} <br>}<br><br><br>3. 확인 정보 팝업 상자를 구현하려면 ajax 방법을 사용하세요. <br>s3capcha.ashx는 서버를 요청할 때 html을 반환하는 데 사용됩니다. <br><br><br><br><br>코드 복사<br><br><br> 코드는 다음과 같습니다.</div> <br><br>public void ProcessRequest(HttpContext context) { <br>context.Response.ContentType = "text/html" <div class="codetitle"> <span>int USession; <a style="CURSOR: pointer" data="8489" class="copybut" id="copybut8489" onclick="doCopy('code8489')">context.Response.Write(s3capcha.GetHtmlCodes(" ../../s3capcha", out USession)) <u>context.Session[s3capcha.s3name] = USession; context.Response.End() </u>}</a></span><br>검증 기능 구현을 위한 verify.ashx 파일 : <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="89926" class="copybut" id="copybut89926" onclick="doCopy('code89926')"><u>코드 복사</u></a></span> 코드는 다음과 같습니다</div> <div class="codebody" id="code89926"> <br>public void ProcessRequest(HttpContext context) <br>{ <br>context.Response.ContentType = "text/plain" <br><br>if (s3capcha.Verify(context.Session[s3capcha.s3name) ], <br>context.Request.Form[s3capcha.s3name])) <br>context.Response.Write("성공") <br>else <br>context.Response.Write("실패") <br><br>context.Response.End(); <br>}<br> </div> <br>JQuery에 Ajax 코드 구현: <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="72173" class="copybut" id="copybut72173" onclick="doCopy('code72173')"><u>코드 복사</u></a></span> 코드는 다음과 같습니다.</div> <div class="codebody" id="code72173"> <br>//Javascript 코드 <br>$(document).ready(function() { <br>getCapcha(); <br> $("form") .bind('submit', function() { <br>$.ajax({ <br>url: 'verify.ashx', <br>type: 'POST', <br>data: { 's3capcha': $ ("input[name=s3capcha]:checked").val() }, <br>캐시: false, <br>성공: function(data) { <br>alert(data); 🎜>getCapcha(); <br>} <br>}); <br>return false <br>});<br><br><br> </div> </div></div><div class="nphpQianMsg"><div class="clear"></div></div><div class="nphpQianSheng"><span>성명:</span><div>본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.</div></div></div><div class="nphpSytBox"><span>이전 기사:<a class="dBlack" title="Javascript 상속 메커니즘_javascript 기술 구현" href="http://m.php.cn/ko/faq/23804.html">Javascript 상속 메커니즘_javascript 기술 구현</a></span><span>다음 기사:<a class="dBlack" title="Javascript 상속 메커니즘_javascript 기술 구현" href="http://m.php.cn/ko/faq/23806.html">Javascript 상속 메커니즘_javascript 기술 구현</a></span></div><div class="nphpSytBox2"><div class="nphpZbktTitle"><h2>관련 기사</h2><em><a href="http://m.php.cn/ko/article.html" class="bBlack"><i>더보기</i><b></b></a></em><div class="clear"></div></div><ins class="adsbygoogle" style="display:block" data-ad-format="fluid" data-ad-layout-key="-6t+ed+2i-1n-4w" data-ad-client="ca-pub-5902227090019525" data-ad-slot="8966999616"></ins><script> (adsbygoogle = window.adsbygoogle || []).push({}); </script><ul class="nphpXgwzList"><li><b></b><a href="http://m.php.cn/ko/faq/1609.html" title="Bootstrap 목록 그룹 구성 요소에 대한 심층 분석" class="aBlack">Bootstrap 목록 그룹 구성 요소에 대한 심층 분석</a><div class="clear"></div></li><li><b></b><a href="http://m.php.cn/ko/faq/1640.html" title="JavaScript 함수 커링에 대한 자세한 설명" class="aBlack">JavaScript 함수 커링에 대한 자세한 설명</a><div class="clear"></div></li><li><b></b><a href="http://m.php.cn/ko/faq/1949.html" title="JS 비밀번호 생성 및 강도 감지의 전체 예(데모 소스 코드 다운로드 포함)" class="aBlack">JS 비밀번호 생성 및 강도 감지의 전체 예(데모 소스 코드 다운로드 포함)</a><div class="clear"></div></li><li><b></b><a href="http://m.php.cn/ko/faq/2248.html" title="Angularjs는 WeChat UI(weui)를 통합합니다." class="aBlack">Angularjs는 WeChat UI(weui)를 통합합니다.</a><div class="clear"></div></li><li><b></b><a href="http://m.php.cn/ko/faq/2351.html" title="JavaScript를 사용하여 중국어 번체와 중국어 간체 간을 빠르게 전환하는 방법과 중국어 간체와 중국어 번체 간 전환을 지원하는 웹사이트의 요령_javascript 기술" class="aBlack">JavaScript를 사용하여 중국어 번체와 중국어 간체 간을 빠르게 전환하는 방법과 중국어 간체와 중국어 번체 간 전환을 지원하는 웹사이트의 요령_javascript 기술</a><div class="clear"></div></li></ul></div></div><ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5902227090019525" data-ad-slot="5027754603"></ins><script> (adsbygoogle = window.adsbygoogle || []).push({}); </script><div class="nphpFoot"><div class="nphpFootBg"><ul class="nphpFootMenu"><li><a href="http://m.php.cn/ko/"><b class="icon1"></b><p>집</p></a></li><li><a href="http://m.php.cn/ko/course.html"><b class="icon2"></b><p>강의</p></a></li><li><a href="http://m.php.cn/ko/wenda.html"><b class="icon4"></b><p>Q&A</p></a></li><li><a href="http://m.php.cn/ko/login"><b class="icon5"></b><p>나의</p></a></li><div class="clear"></div></ul></div></div><div class="nphpYouBox" style="display: none;"><div class="nphpYouBg"><div class="nphpYouTitle"><span onclick="$('.nphpYouBox').hide()"></span><a href="http://m.php.cn/ko/"></a><div class="clear"></div></div><ul class="nphpYouList"><li><a href="http://m.php.cn/ko/"><b class="icon1"></b><span>집</span><div class="clear"></div></a></li><li><a href="http://m.php.cn/ko/course.html"><b class="icon2"></b><span>강의</span><div class="clear"></div></a></li><li><a href="http://m.php.cn/ko/article.html"><b class="icon3"></b><span>기사</span><div class="clear"></div></a></li><li><a href="http://m.php.cn/ko/wenda.html"><b class="icon4"></b><span>Q&A</span><div class="clear"></div></a></li><li><a href="http://m.php.cn/ko/dic.html"><b class="icon6"></b><span>사전</span><div class="clear"></div></a></li><li><a href="http://m.php.cn/ko/course/type/99.html"><b class="icon7"></b><span>수동</span><div class="clear"></div></a></li><li><a href="http://m.php.cn/ko/xiazai/"><b class="icon8"></b><span>다운로드</span><div class="clear"></div></a></li><li><a href="http://m.php.cn/ko/faq/zt" title="주제"><b class="icon12"></b><span>주제</span><div class="clear"></div></a></li><div class="clear"></div></ul></div></div><div class="nphpDing" style="display: none;"><div class="nphpDinglogo"><a href="http://m.php.cn/ko/"></a></div><div class="nphpNavIn1"><div class="swiper-container nphpNavSwiper1"><div class="swiper-wrapper"><div class="swiper-slide"><a href="http://m.php.cn/ko/" >집</a></div><div class="swiper-slide"><a href="http://m.php.cn/ko/article.html" class="hover">기사</a></div><div class="swiper-slide"><a href="http://m.php.cn/ko/wenda.html" >Q&A</a></div><div class="swiper-slide"><a href="http://m.php.cn/ko/course.html" >강의</a></div><div class="swiper-slide"><a href="http://m.php.cn/ko/faq/zt" >주제</a></div><div class="swiper-slide"><a href="http://m.php.cn/ko/xiazai" >다운로드</a></div><div class="swiper-slide"><a href="http://m.php.cn/ko/game" >게임</a></div><div class="swiper-slide"><a href="http://m.php.cn/ko/dic.html" >사전</a></div><div class="clear"></div></div></div><div class="langadivs" ><a href="javascript:;" class="bg4 bglanguage"></a><div class="langadiv" ><a onclick="javascript:setlang('zh-cn');" class="language course-right-orders chooselan " href="javascript:;"><span>简体中文</span><span>(ZH-CN)</span></a><a onclick="javascript:setlang('en');" class="language course-right-orders chooselan " href="javascript:;"><span>English</span><span>(EN)</span></a><a onclick="javascript:setlang('zh-tw');" class="language course-right-orders chooselan " href="javascript:;"><span>繁体中文</span><span>(ZH-TW)</span></a><a onclick="javascript:setlang('ja');" class="language course-right-orders chooselan " href="javascript:;"><span>日本語</span><span>(JA)</span></a><a onclick="javascript:;" class="language course-right-orders chooselan chooselanguage" href="javascript:;"><span>한국어</span><span>(KO)</span></a><a onclick="javascript:setlang('ms');" class="language course-right-orders chooselan " href="javascript:;"><span>Melayu</span><span>(MS)</span></a><a onclick="javascript:setlang('fr');" class="language course-right-orders chooselan " href="javascript:;"><span>Français</span><span>(FR)</span></a><a onclick="javascript:setlang('de');" class="language course-right-orders chooselan " href="javascript:;"><span>Deutsch</span><span>(DE)</span></a></div></div><script> var swiper = new Swiper('.nphpNavSwiper1', { slidesPerView : 'auto', observer: true,//修改swiper自己或子元素时,自动初始化swiper observeParents: true,//修改swiper的父元素时,自动初始化swiper }); </script></div></div><!--顶部导航 end--><script>isLogin = 0;</script><script type="text/javascript" src="/static/layui/layui.js"></script><script type="text/javascript" src="/static/js/global.js?4.9.47"></script></div><script src="https://vdse.bdstatic.com//search-video.v1.min.js"></script><link rel='stylesheet' id='_main-css' href='/static/css/viewer.min.css' type='text/css' media='all'/><script type='text/javascript' src='/static/js/viewer.min.js?1'></script><script type='text/javascript' src='/static/js/jquery-viewer.min.js'></script><script>jQuery.fn.wait = function (func, times, interval) { var _times = times || -1, //100次 _interval = interval || 20, //20毫秒每次 _self = this, _selector = this.selector, //选择器 _iIntervalID; //定时器id if( this.length ){ //如果已经获取到了,就直接执行函数 func && func.call(this); } else { _iIntervalID = setInterval(function() { if(!_times) { //是0就退出 clearInterval(_iIntervalID); } _times <= 0 || _times--; //如果是正数就 -- _self = $(_selector); //再次选择 if( _self.length ) { //判断是否取到 func && func.call(_self); clearInterval(_iIntervalID); } }, _interval); } return this; } $("table.syntaxhighlighter").wait(function() { $('table.syntaxhighlighter').append("<p class='cnblogs_code_footer'><span class='cnblogs_code_footer_icon'></span></p>"); }); $(document).on("click", ".cnblogs_code_footer",function(){ $(this).parents('table.syntaxhighlighter').css('display','inline-table');$(this).hide(); }); $('.nphpQianCont').viewer({navbar:true,title:false,toolbar:false,movable:false,viewed:function(){$('img').click(function(){$('.viewer-close').trigger('click');});}}); </script></body></html>