使用GD库创建验证码,只返回一个数字

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);
?>

It is a minor spelling mistake:

 header('Content-Type: image/jpeg'); 

Instead of

header('content-type = image/jpeg');

http://php.net/manual/en/function.imagettftext.php

Hope to have helped you with this.