Thứ Hai, 22 tháng 8, 2022

Barcode - Chữ Sô


 # Barcode:

unset($_SESSION['barcode']);

session_start();

$string = rand_string(6);

$font_size = 20; 

$_SESSION['barcode'] = $string; 

// $img = imagecreate(338,33);

$img = imagecreate(100,33);

$background = imagecolorallocate($img, 204, 204, 204);

// $text_color = imagecolorallocate($img, 255,255,255);

$text_color = ImageColorAllocate ($img, 51, 51, 255);

imagestring($img, 5,23,8, $string, $text_color);

header("Content-type: image/png");

imagepng($img);

imagedestroy($img);

function rand_string($length) {

$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

$size = strlen($chars);

for( $i = 0; $i < $length; $i++ ) {

  $str .= $chars[ rand( 0, $size - 1 ) ];

}

return $str;

}

# Javascript:

function new_captcha2(){
document.getElementById('imgrandom').src = './classes/barcode.php';
}

# HTML:

<span>
<img src="'.$site_live.'classes/barcode.php" id="imgrandom">
</span>

<a onclick="JavaScript:new_captcha2();" style="padding: 0 20px 0 15px;">
    <i class="fa fa-refresh fontsizeColor"></i>
</a>

<span>
<input type="text" class="form-control fieldses" id=""  name="txt_code" placeholder="Nhập captcha" required  style="display:inline;width:120px;">
</span>

Không có nhận xét nào:

Đăng nhận xét