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&#91;$rand_keys&#91;$i&#93;&#93;;
}
return
substr($output, 0, $this->length);
}

public function
ConvertFontToImage()
{
$type = getimagesize($this->file);
$random = $this->RandomText();
switch (
$type&#91;2&#93
{
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&#91;0&#93; - $textbox&#91;4&#93/2;
$py = ($type&#91;1&#93; - $textbox&#91;5&#93/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&#91;0&#93; - $textbox&#91;4&#93/2;
$py = ($type&#91;1&#93; - $textbox&#91;5&#93/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&#91;0&#93; - $textbox&#91;4&#93/2;
$py = ($type&#91;1&#93; - $textbox&#91;5&#93/2;
imagettftext($im, $this->size, $this->angel, $px, $py, $white, $this->font, $random);
imagepng($im);
imagedestroy($im);
break;
}
$_SESSION&#91;'code'&#93; = $random;
}
}

$handle = new captcha();
if (!empty(
$_GET&#91;'length'&#93) $handle->setLength($_GET&#91;'length'&#93;
if (!empty(
$_GET&#91;'font'&#93) $handle->setFont($_GET&#91;'font'&#93;
if (!empty(
$_GET&#91;'size'&#93) $handle->setSize($_GET&#91;'size'&#93;
if (!empty(
$_GET&#91;'angel'&#93) $handle->setAngel($_GET&#91;'angel'&#93;
if (!empty(
$_GET&#91;'file'&#93) $handle->setFile($_GET&#91;'file'&#93;
$handle->ConvertFontToImage();
?>
</code> </code>

عند استخدامك الكلاس
ستكون صورة الكابتشا على الشكل التالي
مع العلم انك تستطيع تغيير الخلفية ولون ونوع الخط وحتى طول الاحرف في الكلمة





بالنسبة لطريقة الاستخدام، يكفيك دقيقتين تطلع على الملف التطبيقي حتى تفهم طريقة الاستخدام، فهي سهلة جدا

الملفات كاملة بالمرفقات
في الختام، اذا اعجبك الدرس مفصل
فلا تنسانا من دعوة في ظهر الغيب
اخوكم مهند عيسى











الملفات المرفقة [TR]
ca.zip (105.4 كيلوبايت, عدد مرات المشاهدة 277 مرة) [/TR]



©المشاركات المنشورة تعبر عن وجهة نظر صاحبها فقط، ولا تُعبّر بأي شكل من الأشكال عن وجهة نظر إدارة المنتدى©