کد امنیتی

A_pormehr

کاربر عضو
دوستان من این کد امنیتیو دارم ولی میخوام با هر بار ریفرش این کد عوض بشه اگه راهنماییم کنین ممنون میشم

اینم کد

<div id="divtest">28356

کد امنيتي:

<input type="text" size="5" onclick="" id="text_code" required/></div>

 

A_pormehr

کاربر عضو
دوستان یکی راهنمایی کنه ممنون میشم ضروریه

 

baneharshia

تازه وارد
برای استفاده از کد امنیتی باید از php یا JavaScript استفاده کنید

من یه نمونه ساده JavaScript رو معرفی می کنم


کد:
<script type="text/javascript">
    function checkform(theform){        var why = "";                 if(theform.txtInput.value == ""){            why += "کد امنیتی نباید خالی باشد\n";        }        if(theform.txtInput.value != ""){            if(ValidCaptcha(theform.txtInput.value) == false){                why += "- کد امنیتی اشتباه است\n";            }        }        if(why != ""){            alert(why);            return false;        }    } 
//Generates the captcha function        var a = Math.ceil(Math.random() * 9)+ '';    var b = Math.ceil(Math.random() * 9)+ '';           var c = Math.ceil(Math.random() * 9)+ '';      var d = Math.ceil(Math.random() * 9)+ '';      var e = Math.ceil(Math.random() * 9)+ '';            var code = a + b + c + d + e;    document.getElementById("txtCaptcha").value = code;    document.getElementById("txtCaptchaDiv").innerHTML = code;    
// Validate the Entered input aganist the generated security code function   function ValidCaptcha(){    var str1 = removeSpaces(document.getElementById('txtCaptcha').value);    var str2 = removeSpaces(document.getElementById('txtInput').value);    if (str1 == str2){        return true;        }else{        return false;    }}
// Remove the spaces from the entered and generated codefunction removeSpaces(string){    return string.split(' ').join('');}
</script>


کد:
    <p>
      <label for="code">کد رو به رو را وارد کنید > <span id="txtCaptchaDiv" style="color:#F00"></span><!-- this is where the script will place the generated code -->       <input type="hidden" id="txtCaptcha" /></label><!-- this is where the script will place a copy of the code for validation: this is a hidden field -->      <input type="text" name="txtInput" id="txtInput" size="30" />    
</p>

با رفرش کردن صفحه کد امنیتی تغییر می کند
 
آخرین ویرایش توسط مدیر:

A_pormehr

کاربر عضو
مرسی داداش طریقه استفاده هم میشه بگین چطوری استفاده کنم؟کد رو تو فایل index بزنم؟و این دوتا کد که نوشتین مربوط به هم است؟

چون من هر دوتارو پشت سر هم تو فایل indexزدم ولی دکمه ورود میزنی تو سایت بدون خواستن کد امنیتی وارد میشه

ممنون

 
آخرین ویرایش توسط مدیر:

baneharshia

تازه وارد
باید کد جاوا اسکریپت رو قبل از </head> قرار بدید


کد:
<script type="text/javascript">
   function checkform(theform){        var why = "";                 if(theform.txtInput.value == ""){            why += "کد امنیتی نباید خالی باشد\n";        }        if(theform.txtInput.value != ""){            if(ValidCaptcha(theform.txtInput.value) == false){                why += "- کد امنیتی اشتباه است\n";            }        }        if(why != ""){            alert(why);            return false;        }    } 
//Generates the captcha function        var a = Math.ceil(Math.random() * 9)+ '';    var b = Math.ceil(Math.random() * 9)+ '';           var c = Math.ceil(Math.random() * 9)+ '';      var d = Math.ceil(Math.random() * 9)+ '';      var e = Math.ceil(Math.random() * 9)+ '';            var code = a + b + c + d + e;    document.getElementById("txtCaptcha").value = code;    document.getElementById("txtCaptchaDiv").innerHTML = code;    
// Validate the Entered input aganist the generated security code function   function ValidCaptcha(){    var str1 = removeSpaces(document.getElementById('txtCaptcha').value);    var str2 = removeSpaces(document.getElementById('txtInput').value);    if (str1 == str2){        return true;        }else{        return false;    }}
// Remove the spaces from the entered and generated codefunction removeSpaces(string){    return string.split(' ').join('');}
</script>
و کد html رو در جایی که میخوایید نشون داده بشه رو قرار بدید


کد:
  <p>
      <label for="code">کد رو به رو را وارد کنید > <span id="txtCaptchaDiv" style="color:#F00"></span><!-- this is where the script will place the generated code -->       <input type="hidden" id="txtCaptcha" /></label><!-- this is where the script will place a copy of the code for validation: this is a hidden field -->      <input type="text" name="txtInput" id="txtInput" size="30" />    
</p>
 

A_pormehr

کاربر عضو
داداش طبق گفته شما میزنم ولی کدی نمایش داده نمیشه هیچ اسم رو هم که وارد میکنی بدون خواستن کد امنیتی وارد مرحله بعد میشه

کدی که خودم دادمو تو سایت استفاده کردم این آدرس برین متوجه میشین منظورم چیه

فقط میخوام اون عدد تغیر کنه با هر بار رفرش :53:

 

baneharshia

تازه وارد
کد بدرستی کار میکنه در زیر یه نمونه از فرم با همین کد رو برای دانلود قرار دادم می تونید از این نمونه استفاده کنید.



 

A_pormehr

کاربر عضو
مرسی داداش درستش کردم یه تیکه از کد مشل داشت که از کد خودم گذاشتم درست شد

این کد مشکل داشت

<input type="text" name="txtInput" id="txtInput" size="30" />

که اینو جاش گذاشتم درست شد

<input type="text" size="5" onclick="" id="text_code" required/>

ولی در کل شما کمکم کردی خیلی ممنون :53:

 

agahassan

کاربر عضو
لطفا کدو داخل ویرایش گر بذارید

ممنون بابت انتشار ولی نکته این کد اینه که اسکریپتش باید داخل بادی قرار بگیره تا عمل کنه نه داقل هید یعنی به این صورتم قرار بدی عمل میکنه


کد:
 <label for="code"><span id="txtCaptchaDiv" style="color:#F00"></span> < کد رو به رو را وارد کنید
      <input type="hidden" id="txtCaptcha" /></label>
      <input type="text" name="txtInput" id="txtInput" size="30" />
   <script type="text/javascript">
    function checkform(theform){
        var why = "";

        if(theform.txtInput.value == ""){
            why += "- Security code should not be empty.\n";
        }
        if(theform.txtInput.value != ""){
            if(ValidCaptcha(theform.txtInput.value) == false){
                why += "- Security code did not match.\n";
            }
        }
        if(why != ""){
            alert(why);
            return false;
        }
    }


//Generates the captcha function    
    var a = Math.ceil(Math.random() * 9)+ '';
    var b = Math.ceil(Math.random() * 9)+ '';       
    var c = Math.ceil(Math.random() * 9)+ '';  
    var d = Math.ceil(Math.random() * 9)+ '';  
    var e = Math.ceil(Math.random() * 9)+ '';  

    var code = a + b + c + d + e;
    document.getElementById("txtCaptcha").value = code;
    document.getElementById("txtCaptchaDiv").innerHTML = code;    

// Validate the Entered input aganist the generated security code function   
function ValidCaptcha(){
    var str1 = removeSpaces(document.getElementById('txtCaptcha').value);
    var str2 = removeSpaces(document.getElementById('txtInput').value);
    if (str1 == str2){
        return true;    
    }else{
        return false;
    }
}

// Remove the spaces from the entered and generated code
function removeSpaces(string){
    return string.split(' ').join('');
}
</script>
 

agahassan

کاربر عضو
البته کد کاربردی نیست و اسپمر به راحتی ازش رد شد :40:

کسی بهترشو سراغ نداره ؟

 

baneharshia

تازه وارد
کد امنیتی پ اچ پی

از این نمونه استفاده کنید

لینک دانلود:

 

zegersot

کاربر عضو
این کد امنیتی نصب نمیخواد !

توی فایل index.php نمونه استفاده شده رو گذاشته شده یه نگاهی بندازید

موفق باشید

 
بالا