منتدى استراحات زايد

منتدى استراحات زايد (http://vb.ma7room.com/index.php)
-   منتدى أخبار المواقع والمنتديات العربية والأجنبية (http://vb.ma7room.com/forumdisplay.php?f=183)
-   -   [ درس ] برمجة كابتشا تعمل بالصور (http://vb.ma7room.com/showthread.php?t=1415494)

محروم.كوم 03-14-2014 11:10 PM

[ درس ] برمجة كابتشا تعمل بالصور
 
<div>
درس بسيط عن كيفية برمجة كابتشا تعتمد على التعرف على شكل ما

مثال:

http://4techs.org/wp-content/uploads...3/captcha1.png

ما فائدة الكابتشا؟
تمنع السبام و البوت من التسجيل على موقعك او اضافة محتوى الخ..

لماذا كابتشا تعتمد على صور و ليس التعرف على نص؟
ببساطة الكابتشا التي تعتمد على التعرف على نص ممكن يتجاوزها البوت بسهول بأستخدام تقنية اسمها OCR او Optical Character Recognition التي تستطيع التعرف على اي نص داخل صورة و لهذا السبب يفضل ان لا تستخدم كابتشا تعتمد على التعرف على نص

المتطلبات:
تجميعة بسيطة لأشكال ليتعرف عليها الزائر.. مثلاً 5 صور لـ قطط او 5 صور لـ سيارة او 5 صور لـ كومبيوتر الخ

الكود:
اولاً.. نبني المتغيرات التي ممكن للذي يحب ستخدم الكابتشا ان يغيرها
رمز PHP:
// User must set these
$objects = array("bed", "bird", "book", "cable", "car", "chair", "computer", "currency", "dog", "flowers");
$offset = array("min" => 1, "max" => 5);
$num_solutions = 3;
$num_options = 3;


المتغير $objects هو مصفوفة تضع فيها كل الاشكال
المتغير $offset هو مصفوفه فيها عدد الصور لكل شكل
مثلاً لو عندي 5 صور مرقمة على شكل cat-1 cat-2 cat-3 cat-4 cat-4 اضع min واحد و max خمسة
المتغير $num_solutions تضع فيه عدد الاشكال التي تريد ان يتعرف عليها الزائر
المتغير $num_options هو عدد الخيارات لكل شكل

ثانياً.. نبدأ الجلسة و نفتح مصوفتين فارغات
رمز PHP:
// Do not mess with these
session_start();
$captchas = array();
$_SESSION['captcha_solutions'] = array();


ثالثاً.. نختار الاشكال للتعرف عليها من مصفوفة الاشكال على العدد الذي اختاره مستخدم السكريبت
رمز PHP:
<span style="color: #000000">// Shuffle the array and pick $num_solutions objects
shuffle($objects);
for(
$i = 0; $i <span style="color: #007700">// Display the pictures of the captcha
foreach($captchas as $captcha) {

// Build a temp array of objects
$temp = $objects;
$key = array_search($captcha, $objects);
unset(
$temp[$key]);
shuffle($temp);

// Build a list of options
$options = array();
for(
$i = 0; $i

imagefilter($image, IMG_FILTER_GAUSSIAN_BLUR);
imagefilter($image, IMG_FILTER_PIXELATE, 1, true);
imagefilter($image, IMG_FILTER_MEAN_REMOVAL);

// Generate the output of the image, encode it and include it as a data URI
ob_start();
imagejpeg($image);
$base64 = base64_encode(ob_get_contents());
ob_end_clean();

echo
"

"
;
foreach(
$options as $option) echo "$option";
echo
"

"
;

// Save the solution to an array of solutions
$_SESSION['captcha_solutions'][] = $captcha;

}


و الآن نذهب للكود المستخدم للتحقق من صحة الادخال

<div style="margin:20px; margin-top:5px"> رمز PHP:
<div class="alt2"> <div dir="ltr" style="text-align:left;"> <span style="color: #000000"> session_start();

$answers_user = $_POST['captcha'];
$answers_correct = $_SESSION['captcha_solutions'];
$num_correct = count($answers_correct);
$correct = 0;

for(
$i = 0; $i <span style="color: #007700">


الساعة الآن 10:48 AM

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.5.2 TranZ By Almuhajir


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227