PDA

View Full Version : سوال: چرخش متن در کد امنیتی



farnaz.saeedi
شنبه 08 بهمن 1390, 11:47 صبح
سلام
من از این کد برای تولید کد امنیتی استفاده میکنم اما الان اعداد بصورت ساده و معمولی نشون داده میشن
چطوری میتونم اعداد و کج و کوله نشون بدم یجوری که خوندنش سخت بشه؟
این صفحه gd.php


<?php
header("Content-type: image/png");
$string = $_GET['text'];
$im = imagecreatefrompng("img/capcha.png");
$orange = imagecolorallocate($im, 100, 210, 60);
$px = (imagesx($im) - 8 * strlen($string)) / 2;
imagestring($im,9, $px, 9, $string, $orange);
imagepng($im);
imagedestroy($im);
?>

این کدم تو صفحه ثبت نام دارم


<img src="gd.php?text=<?php echo $code;?>" />

الان به این شکله:
81591

tux-world
شنبه 08 بهمن 1390, 14:32 عصر
خود ایجاد کننده کپچا:

<?php
session_start();
//Settings: You can customize the captcha here
$image_width = 120;
$image_height = 35;
$characters_on_image = 6;
$font = './monofont.ttf';

//The characters that can be used in the CAPTCHA code.
//avoid confusing characters (l 1 and i for example)
$possible_letters = '23456789bcdfghjkmnpqrstvwxyz';
$random_dots = 0;
$random_lines = 20;
$captcha_text_color="0x142864";
$captcha_noice_color = "0x142864";

$code = '';


$i = 0;
while ($i < $characters_on_image) {
$code .= substr($possible_letters, mt_rand(0, strlen($possible_letters)-1), 1);
$i++;
}


$font_size = $image_height * 0.75;
$image = @imagecreate($image_width, $image_height);


/* setting the background, text and noise colours here */
$background_color = imagecolorallocate($image, 255, 255, 255);

$arr_text_color = hexrgb($captcha_text_color);
$text_color = imagecolorallocate($image, $arr_text_color['red'],
$arr_text_color['green'], $arr_text_color['blue']);

$arr_noice_color = hexrgb($captcha_noice_color);
$image_noise_color = imagecolorallocate($image, $arr_noice_color['red'],
$arr_noice_color['green'], $arr_noice_color['blue']);


/* generating the dots randomly in background */
for( $i=0; $i<$random_dots; $i++ ) {
imagefilledellipse($image, mt_rand(0,$image_width),
mt_rand(0,$image_height), 2, 3, $image_noise_color);
}


/* generating lines randomly in background of image */
for( $i=0; $i<$random_lines; $i++ ) {
imageline($image, mt_rand(0,$image_width), mt_rand(0,$image_height),
mt_rand(0,$image_width), mt_rand(0,$image_height), $image_noise_color);
}


/* create a text box and add 6 letters code in it */
$textbox = imagettfbbox($font_size, 0, $font, $code);
$x = ($image_width - $textbox[4])/2;
$y = ($image_height - $textbox[5])/2;
imagettftext($image, $font_size, 0, $x, $y, $text_color, $font , $code);


/* Show captcha image in the page html page */
header('Content-Type: image/jpeg');// defining the image type to be shown in browser widow
imagejpeg($image);//showing the image
imagedestroy($image);//destroying the image instance
$_SESSION['6_letters_code'] = $code;

function hexrgb ($hexstr)
{
$int = hexdec($hexstr);

return array("red" => 0xFF & ($int >> 0x10),
"green" => 0xFF & ($int >> 0x8),
"blue" => 0xFF & $int);
}
?>
طرز استفاده:

<img src="captcha_code_file.php?rand=<?php echo rand(); ?>

farnaz.saeedi
شنبه 08 بهمن 1390, 18:42 عصر
سلام
این که شما میگید درست,من بخوام از کدی که خودم گذاشتم استفاده کنم چطوری باید تغییرش بدم که حروف رو بصورت کج و ناخوانا نمایش بده؟

yones_safari
شنبه 08 بهمن 1390, 19:11 عصر
درود به جای تابع imagestring از تابع زیر استفاده کن:

imagefttext("$im","اندازه متن","زاویه چرخش","x","y","رنگ متن","نام فونت","متن مورد نظر");
که به جای زاویه چرخش اگه اعدد مثبت قرار بدی به طرف راست و اگه منفی قرار بدی به سمت چپ میچرخه.مثلا +5 بدی به سمت راست خم میشه.برای اینکه جالب بشه از تابع رندوم مثلا در یک محدوده خاص استفاده کن .مثلا از -5 تا +5 استفاده کن تا سخت بشه.در ضمن به جای x و y سطر و ستون جایی که میخوای حروف قرار بگیره رو قرار بده.فونت رو هم جایی کپی کن که فایلت اونجاست و نامش رو هم در فیلد مربوطه وارد کن.
موفق باشی

tux-world
شنبه 08 بهمن 1390, 19:16 عصر
این کد رو ببین:

$degrees = 180;
// Content type
header('Content-type: image/jpeg');
// Load
$source = imagecreatefromjpeg($filename);
// Rotate
$rotate = imagerotate($source, $degrees, 0);
اون 180 ای که هست میزان چرخش رو تعیین میکنه

MMSHFE
یک شنبه 09 بهمن 1390, 10:34 صبح
با سلام، این همون کد شماست که تغییرش دادم. ببینید چطوره؟


header('Content-type: image/png');
$im = imagecreatefrompng('img/capcha.png');
$im = imagecreate(120, 35);
$w = imagesx($im);
$h = imagesy($im);
$string = $_GET['text'];
$font = './tahoma.ttf';
$fontsize = $h * 0.5;
$len = strlen($string);
$background = imagecolorallocate($im, 100, 210, 60);
$foreground = imagecolorallocate($im, 0, 0, 255);
$px = ($w - 15 * $len) / 2;
$box = imagettfbbox($fontsize, 0, $font, $string);
$direction = 1;
for($i = 0; $i < $len; $i++) {
imagettftext($im, $fontsize, (rand() % 30 * $direction), $px, ($h - $box[5]) / 2 - 2, $foreground, $font, substr($string, $i, 1));
$direction = -$direction;
$px += 15;
}
imagepng($im);
imagedestroy($im);

نکته: فونت Tahoma رو از پوشه Fonts ویندوز در کنار اسکریپت قرار بدین. موفق باشید.

mbf5923
یک شنبه 09 بهمن 1390, 10:57 صبح
سلام
اگه ما بخوایم روی همین عکس حروف فارسی بنویسیم باید چیکار کنیم
چنذ جا در موردش صحبت شده ولی من به نتیجه نرسیدم

tux-world
یک شنبه 09 بهمن 1390, 11:52 صبح
بايد از GD استفاده كنيد كه تو سايت اكسيژن يكي از بچه ها معرفي كرده بودن كه چيكار بايد بكنيد

mbf5923
یک شنبه 09 بهمن 1390, 12:24 عصر
توضیحی میخواستم دوست من که چطور مشه این کار رو کرد
کلاس آماده برای این کار نمیخوام