title: Uninitialized string offset: 62
body: <p>So I'm in the early stages of trying to make a little captcha thing as practise. </p>
  
  <p>My code thus far, for the image generation:</p>
  
  <pre><code>session_start();
  header('Content-type: image/jpeg');
  
  $string = $_SESSION['secure'];
  $font_size = 5;
  $image_width = ImageFontWidth($font_size)*strlen($string);
  $image_height = ImageFontHeight($font_size);
  
  $image = imagecreate($image_width, $image_height);
  imagecolorallocate($image, 255, 255, 255);
  $font_colour = imagecolorallocate($image, 0, 0, 0);
  
  imagestring($image, $font_size, 0, 0, $string, $font_colour);
  imagejpeg($image);
  </code></pre>
  
  <p>And the code for the form itself (function is in separate file (rand.php)):</p>
  
  <pre><code>function random_string($length = 10){
      $alphnum = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
      $alphnum_length = strlen($alphnum);
      $random_string = '';
  
      for ($i=0; $i &lt; $length; $i++) { 
          $random_string.= $alphnum[rand(0, $alphnum_length)];
      }
      return $random_string;
  
  }
  
  require('../rand.php'); 
  
  $_SESSION['secure'] = random_string(5);
  echo $_SESSION['secure'];
  </code></pre>
  
  <p>Now it generates a random string, and on the generate image page an image is indeed generated. I've not yet gotten to outputting the image on the form page but thats not the issue.</p>
  
  <p>The issue is every 20 or so refreshes of the form page (the page thats only currently outputting the random_string) I get an error stating:</p>
  
  <p>( ! ) Notice: Uninitialized string offset: 62 in C:Sandbox\gd\rand.php on line 10</p>
  
  <p>I get this error, and instead of the usual 5 character length string I only get 4.</p>
  
  <p>I'm fairly new so I've not the wherewithal to debug this myself. Please could you offer some advice?</p>