استعمل مربع البحث في الاسفل لمزيد من المواضيع
سريع للبحث عن مواضيع في المنتدى
-
11-01-2013, بتوقيت غرينيتش 03:41 PM
#1
captcha (التحقق بالصورة) كلاس بسيط وفيه ميزات ممتازة
captcha (ط§ظ„طھط*ظ‚ظ‚ ط¨ط§ظ„طµظˆط±ط©) ظƒظ„ط§ط³ ط¨ط³ظٹط· ظˆظپظٹظ‡ ظ…ظٹط²ط§طھ ظ…ظ…طھط§ط²ط©
السلام عليكم ورحمة الله وبركاته
كيف حالكم، ان شاء الله بخير؟
نبدا بموضوعنا
- اسم الكلاس: captcha.php
- وظيفة الكلاس: وظيفته توليد صورة بارقام عشوائية للتحقق البشري.
- ميزات الكلاس: يتميز الكلاس بميزات كثيرة ومنها امكانية تغيير صور الخلفيات للكابتشا، بالاضافة لامكانية اضافة ملفات خطوط لتغيير الخط على الصورة، وايضا يوفر لك الكتابة مائلة بدرجة تحددها نت لزيادة الامان، وامكانية تكبير وتصغير حجم الخط، والمزيد من الميزات، اكتشفها بنفسك
- ملاحظة: الملف المرفق يحتوي على ملف الكلاس + ملف تجريبي + ملف الخط المستخدم وهو georgia بالاضافة الى صورة الخلفية، يمكنك تغييرها حيث ان الكلاس يدعم جيف وجبج وبنغ، الحزمة بكاملها في المرفقات
كود code الكلاس:
رمز PHP:
<code style="white-space:nowrap"> <code>
<?php
/**
* @author Dodit Suprianto
* Email: [email protected]
* Website: http://doditsuprianto.com, http://goiklan.co.nr
* Website: http://www.meozit.com, http://easyads.co.nr
*
* call captcha code <img src=captcha.class.php?length=&font=&size=&angel=&f ile=>
*
* You can enter the parameter or not. Explaination:
*
* length : how much character will be shown. 4 character by default.
* font : Type of font (ex. Arial.ttf). Georgia font by default
* size : Size of font character. 20 by default
* angel : angel of font character. 0 by default, it means horizontal position
* file : if you want subtitute the background image. "eyes.gif" by default.
*
* You must copy several file to current directory
* if you want to subtitute the default setting.
* such as font file, background file
*
*/
session_start();
class captcha
{
private $length;
private $font;
private $size;
private $angel;
private $file;
public function __construct()
{
$this->length = 4;
$this->font = "georgia.ttf";
$this->size = 20;
$this->angel = 0;
$this->file = "eyes.gif";
}
public function setFile($file)
{
$this->file = $file;
}
public function setLength($length)
{
$this->length = $length;
}
public function setFont($font)
{
$this->font = $font;
}
public function setSize($size)
{
$this->size = $size;
}
public function setAngel($angel)
{
$this->angel = $angel;
}
private function RandomText()
{
$output = "";
$input = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','1','2','3','4','5','6','7','8','9');
srand((float) microtime() * 10000000);
$rand_keys = array_rand($input, count($input));
for ($i=0; $i < count($input)-1; $i++)
{
$output .= $input[$rand_keys[$i]];
}
return substr($output, 0, $this->length);
}
public function ConvertFontToImage()
{
$type = getimagesize($this->file);
$random = $this->RandomText();
switch ($type[2]
{
case IMAGETYPE_GIF:
header("Content-type: image/gif");
$im = imagecreatefromgif($this->file);
$white = imagecolorallocate($im, 255, 255, 255);
$textbox = imagettfbbox($this->size, 0, $this->font, $this->RandomText());
$px = ($type[0] - $textbox[4]
/2;
$py = ($type[1] - $textbox[5]
/2;
imagettftext($im, $this->size, $this->angel, $px, $py, $white, $this->font, $random);
imagegif($im);
imagedestroy($im);
break;
case IMAGETYPE_JPEG:
header("Content-type: image/jpeg");
$im = imagecreatefromjpeg($this->file);
$white = imagecolorallocate($im, 255, 255, 255);
$textbox = imagettfbbox($this->size, 0, $this->font, $this->RandomText());
$px = ($type[0] - $textbox[4]
/2;
$py = ($type[1] - $textbox[5]
/2;
imagettftext($im, $this->size, $this->angel, $px, $py, $white, $this->font, $random);
imagejpeg($im);
imagedestroy($im);
break;
case IMAGETYPE_PNG:
header("Content-type: image/png");
$im = imagecreatefrompng($this->file);
$white = imagecolorallocate($im, 255, 255, 255);
$textbox = imagettfbbox($this->size, 0, $this->font, $this->RandomText());
$px = ($type[0] - $textbox[4]
/2;
$py = ($type[1] - $textbox[5]
/2;
imagettftext($im, $this->size, $this->angel, $px, $py, $white, $this->font, $random);
imagepng($im);
imagedestroy($im);
break;
}
$_SESSION['code'] = $random;
}
}
$handle = new captcha();
if (!empty($_GET['length']
) $handle->setLength($_GET['length']
;
if (!empty($_GET['font']
) $handle->setFont($_GET['font']
;
if (!empty($_GET['size']
) $handle->setSize($_GET['size']
;
if (!empty($_GET['angel']
) $handle->setAngel($_GET['angel']
;
if (!empty($_GET['file']
) $handle->setFile($_GET['file']
;
$handle->ConvertFontToImage();
?> </code> </code>
عند استخدامك الكلاس
ستكون صورة الكابتشا على الشكل التالي
مع العلم انك تستطيع تغيير الخلفية ولون ونوع الخط وحتى طول الاحرف في الكلمة

بالنسبة لطريقة الاستخدام، يكفيك دقيقتين تطلع على الملف التطبيقي حتى تفهم طريقة الاستخدام، فهي سهلة جدا
الملفات كاملة بالمرفقات
في الختام، اذا اعجبك الدرس مفصل
فلا تنسانا من دعوة في ظهر الغيب
اخوكم مهند عيسى
الملفات المرفقة [TR]
ca.zip (105.4 كيلوبايت, عدد مرات المشاهدة 277 مرة) [/TR]

©المشاركات المنشورة تعبر عن وجهة نظر صاحبها فقط، ولا تُعبّر بأي شكل من الأشكال عن وجهة نظر إدارة المنتدى©
المواضيع المتشابهه
-
بواسطة walid في المنتدى لغات البرمجه للويب
مشاركات: 0
آخر مشاركة: 11-01-2013, بتوقيت غرينيتش 04:08 PM
-
بواسطة said في المنتدى لغات البرمجه للويب
مشاركات: 0
آخر مشاركة: 11-01-2013, بتوقيت غرينيتش 03:52 PM
-
بواسطة Chakira في المنتدى لغات البرمجه للويب
مشاركات: 0
آخر مشاركة: 11-01-2013, بتوقيت غرينيتش 02:35 PM
-
بواسطة romaissa في المنتدى لغات البرمجه للويب
مشاركات: 0
آخر مشاركة: 11-01-2013, بتوقيت غرينيتش 02:16 PM
-
بواسطة admin في المنتدى لغات البرمجه للويب
مشاركات: 0
آخر مشاركة: 11-01-2013, بتوقيت غرينيتش 10:02 AM
ضوابط المشاركة
- لا تستطيع إضافة مواضيع جديدة
- لا تستطيع الرد على المواضيع
- لا تستطيع إرفاق ملفات
- لا تستطيع تعديل مشاركاتك
-
قوانين المنتدى