بسم الله الرحمن الرحيم ،،
السلام عليكم ورحمة الله وبركاته ,,
اللهم علمنا بمانفعتنا وانفعنا بماعلمتنا وزدنا علما ياقدير ..
اليوم بإذن الله سأشرح لكم طريقة مميزة لعلها لاتكون مكررة .. وتفيدكم بإذن الله في سكربتاكم الخاصة ..
ماهي ال Captcha ؟
لعلك حينما تبحث في جوجل سيظهر لك أول واحد هذا الرابط
http://en.wikipedia.org/wiki/Captcha ..
وفيه نبذه عنها وهي بشكل مختصر صوره يتم كتابتها ديناميكيا بواسطة أحد لغات السيرفر
الهدف منها تقليص المدخلات المزعجة والتي تهدف العبث بموقعك ..
الحقيقة ولا اخفيكم انا واجهت مشاكل في نموذج إرسال صممت لاحد المواقع وكان كل يوم على الأقل رسالة رسالتين سبام ..
المهم ندخل في الموضوع وخطوات الدرس بإذن الله :
اولا افتح الفوتوشوب وصمم لك صوره بمقاس 87 * 18 ويكون تصميم نوعا ما هادئ ..
مثال :
واحفظها بصيغة png باسم captcha
ثانياً أنشى ملف بإسم captcha.php
وهذا محتواه :
كود PHP:
<?php
//Start the session so we can store what the code actually is.
session_start();
//Now lets use md5 to generate a totally random string
$md5 = md5(microtime() * mktime());
/*
We dont need a 32 character long string so we trim it down to 5
*/
$string = substr($md5,0,5);
/*
Now for the GD stuff, for ease of use lets create
the image from a background image.
*/
$captcha = imagecreatefrompng("./captcha.png");
/*
Hxdec_arr : Transform hexcolor to 255 format.
@color : color format without '#' .
@return Array
*/
function Hxdec_arr($color){
$int = hexdec($color);
$arr = array("red" => 0xFF & ($int >> 0x10),
"green" => 0xFF & ($int >> 0x8),
"blue" => 0xFF & $int);
return $arr;
}
/*
Lets set the colours, the colour $line is used to generate lines.
Using a blue misty colours. The colour codes are in RGB
*/
$black = imagecolorallocate($captcha, 0, 0, 0);
$c1 = Hxdec_arr('DAEDF6');
$c2 = Hxdec_arr('9CB7C4');
$line = imagecolorallocate($captcha,$c1["red"],$c1["green"],$c1["blue"]);
$line2 = imagecolorallocate($captcha,$c2["red"],$c2["green"],$c2["blue"]);
/*
Now to make it a little bit harder for any bots to break,
assuming they can break it so far. Lets add some lines
in (static lines) to attempt to make the bots life a little harder
*/
imageline($captcha,0,0,39,29,$line);
imageline($captcha,-100,57,34,8,$line2);
imageline($captcha,0,0,39,29,$line);
imageline($captcha,40,0,64,29,$line2);
/*
Now for the all important writing of the randomly generated string to the image.
*/
imagestring($captcha,5, 20, 1, $string, $black);
/*
Encrypt and store the key inside of a session
*/
$_SESSION['key'] = md5($string);
/*
Output the image
*/
header("Content-type: image/png");
imagepng($captcha);
?>
وملفك اللي فيه الفورم أضف عليه الصوره وحقل باسم code :
كود HTML:
<input name="code" type="text" /><img src="captcha.php" alt="فضلا انقل الموجود بالصوره" />
أخيرا ملفك اللي موجه له الفورم :
تستعمل فيه التشييك التالي :
كود PHP:
if(md5($_POST['code']) != $_SESSION['key'])
die("عفوا كود خاطئ!");
else
echo 'لقد أدخلت الكود بشكل صحيحّ!';
ولا تنسى يكون في بدايه ملفاتك تضع بداية للسسيشن اذا كان عندك ملف header.php او global تضع في اوله
كود PHP:
session_start();
ملف للتجريب للي مافهم : test.php :
كود PHP:
<?
session_start();
if ($_GET['a'] =='check' && $_POST){
if(md5($_POST['code']) != $_SESSION['key'])
die("عفوا كود خاطئ!");
else
echo 'لقد أدخلت الكود بشكل صحيحّ!';
}
?>
<form action="?a=check" method="post">
<input name="code" type="text" /><img src="captcha.php" /><br />
<input type="submit" name="submit" value="Submit" />
</form>
مثال :
http://www.artsisland.net/flasher/up...ptcha/test.php
لي عودة بإذن الله لمن لديه استفسار ..
روابط ذو صله :
http://codewalkers.com/tutorials/95
http://www.planet-source-code.com/vb...d=739&lngWId=8
ولانسونا من صالح دعائكم ،
المشرف التقني على موقع رياض القرآن.