title: Captcha is not showing up in php
body: <p>I am trying to create a captcha that takes words from a file I've named dictionary.txt and uses GD Library to turn them into captcha images. But something is wrong. I can get my dictionary phrases to show up as session variables but they won't make an image. So it must be the GD Library code. There is a final target file named captcha_validate.php but that's not important right now. I am just trying to get the image to work.</p>
  
  <p><strong>form_captcha.php</strong></p>
  
  <pre><code>&lt;form class="" action="captcha_validate.php" method="post"&gt;
      Captcha Verify:
      &lt;input type="text" name="captcha" value="" /&gt;&lt;br /&gt;&lt;br /&gt;
      &lt;img src="captcha.php" /&gt;&lt;br /&gt;
      &lt;input type="submit" name="submit" value="Submit" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>captcha.php</strong></p>
  
  <pre><code>    &lt;?php
  
      session_start();
  
      session_regenerate_id();
  
      $file = file('dictionary.txt', FILE_IGNORE_NEW_LINES);
  
      $length = count($file) - 1;
      $random = rand(0, $length);
  
      $_SESSION['captcha'] = $file[$random];
      session_write_close();
  
      function msg($msg) {
          $container = imagecreate(250, 170);
          $black = imagecolorallocate($container, 0, 0, 0);
          $white = imagecolorallocate($container, 255, 255, 255);
          $font = "C:\Windows\Fonts\arial.ttf";
          imagefilledrectangle($container, 0, 0, 250, 170, $black);
  
          $px = (imagesx($container) / (strlen($msg)/1.15));
          $py = (imagesy($container) / 3.5);
  
          imagefttext($container, 28, -27, $px, $py, $white, $font, $msg);
          header("Content-type: image/png");
          imagepng($container, null);
          imagedestroy($container);
      }
  
      msg($file[$random]);
  
       ?&gt;
  </code></pre>