I am new to PHP. When I check index.php
it doesn't generate random number, rather it generates sames number all the time when refreshing the page. I use XAMPP v3.2.2
and GD library seems to be pre-installed, so what seems to be problem.
My index.php
:
<?php
ob_start();
$_SESSION['secure'] = rand(1000,9999);
?>
<img src="generate.php"/>
My generate.php
:
<?php
session_start();
header('content-type = image/jpeg');
$text = $_SESSION['secure'];
$font_size = 30;
$image_width = 300;
$image_height = 100;
$image = imagecreate($image_width, $image_height);
imagecolorallocate($image, 211, 211, 211);
$text_color = imagecolorallocate($image, 0, 0, 0);
imagettftext($image, $font_size, 0, 30, 55, $text_color, 'font.ttf', $text);
imagejpeg($image);
?>