Tasodifiy harflar va raqamlarni birlashtirish

Sizning tasodifiy sonlar sifatida tasodifiy harflaringizni qanday qilib qo'shishni bilasizmi? yordam uchun rahmat.

<?php 
session_start(); 
$image = imagecreate(, ); 
$bgcolor = imagecolorallocate($image, , ,);
$textcolor = imagecolorallocate($image, , , ); 
$code = rand(00, 99); 




$_SESSION['code'] = ($code);
imagestring($image, , , , $code, $textcolor); 
header ("Content-type: image/png"); 
imagepng($image);
?>
1
qo'shib qo'ydi muallif aebersold, manba

6 javoblar

Men buni md5 yordamida tasodifiy harflar va raqamlar uchun qilishni yaxshi ko'raman. uning to'liq tasodifiy emasligi, lekin u har ikkala raqam va harflar bilan birga tasodifiy qatorni qaytaradi.

$i = rand(100000000, 9999999999)
$i = md5($i);           //creates a hashed string with 32 characters
$i = str_split($i, 10); //10 is the amount of characters of your string max 32
$i = $i[0];
1
qo'shib qo'ydi

Men buni md5 yordamida tasodifiy harflar va raqamlar uchun qilishni yaxshi ko'raman. uning to'liq tasodifiy emasligi, lekin u har ikkala raqam va harflar bilan birga tasodifiy qatorni qaytaradi.

$i = rand(100000000, 9999999999)
$i = md5($i);           //creates a hashed string with 32 characters
$i = str_split($i, 10); //10 is the amount of characters of your string max 32
$i = $i[0];
1
qo'shib qo'ydi

Buning uchun funksiya bor

function createRandomString() {
    $chars = "abcdefghijkmnopqrstuvwxyz023456789";
    srand((double)microtime()*1000000);
    $i = 0;
    $randomstring = '' ;

    while ($i <= 7) {
        $num = rand() % 33;
        $tmp = substr($chars, $num, 1);
        $randomstring = $randomstring . $tmp;
        $i++;
    }

    return $randomstring;

}

echo createRandomString();
0
qo'shib qo'ydi

Buning uchun funksiya bor

function createRandomString() {
    $chars = "abcdefghijkmnopqrstuvwxyz023456789";
    srand((double)microtime()*1000000);
    $i = 0;
    $randomstring = '' ;

    while ($i <= 7) {
        $num = rand() % 33;
        $tmp = substr($chars, $num, 1);
        $randomstring = $randomstring . $tmp;
        $i++;
    }

    return $randomstring;

}

echo createRandomString();
0
qo'shib qo'ydi

Siz shunday qila olasiz.

<?php
$code = substr(md5(microtime()),rand(0,26),10);
$im = imagecreate(100, 30);
$bg = imagecolorallocate($im, 255, 255, 255);
$textcolor = imagecolorallocate($im, 0, 0, 0);
imagestring($im, 5, 0, 0, $code, $textcolor);
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>

Amaldagi manbalar:

https://stackoverflow.com/a/5438778/1978142
http://www.php.net//manual/en/function.imagestring.php

0
qo'shib qo'ydi
Rahmat!
qo'shib qo'ydi muallif user1, manba

Siz shunday qila olasiz.

<?php
$code = substr(md5(microtime()),rand(0,26),10);
$im = imagecreate(100, 30);
$bg = imagecolorallocate($im, 255, 255, 255);
$textcolor = imagecolorallocate($im, 0, 0, 0);
imagestring($im, 5, 0, 0, $code, $textcolor);
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>

Amaldagi manbalar:

https://stackoverflow.com/a/5438778/1978142
http://www.php.net//manual/en/function.imagestring.php

0
qo'shib qo'ydi
Rahmat!
qo'shib qo'ydi muallif user1, manba
PhP |BotsUz
PhP |BotsUz
93 ishtirokchilar

Phpni o'rganishni Hohlasangiz https://t.me/joinchat/AAAAAE-KRc5dd5tPMmGmWA A'zo bo'lin