title: Create image captcha with PHP
body: <p>Hi i want to create a image captcha with <a href="/questions/tagged/php" class="post-tag" title="show questions tagged &#39;php&#39;" rel="tag">php</a>, i have the next code for my form.</p>
  
  <pre><code>&lt;form action="" method="POST"&gt;
      &lt;div class="label_form"&gt;Usuario:&lt;/div&gt; &lt;input type="text" name="user"/&gt;&lt;br&gt;
      &lt;div class="label_form"&gt;Contraseña:&lt;/div&gt; &lt;input type="password" name="pass"/&gt;&lt;br&gt;  
      &lt;img alt="Numeros aleatorios" src="layouts/captcha.php" /&gt;  
      &lt;input class="label_form" type="text" name="num"/&gt;&lt;br&gt;
      &lt;input type="submit" value="ENTRAR" name="submit"/&gt;
  &lt;/form&gt; 
  </code></pre>
  
  <p>This is the code for validation before to send the form:</p>
  
  <pre><code>if (isset($_POST["submit"])) {
    if ($_SESSION['img_number'] != $_POST['num']) {
      echo "&lt;div class='msg_error'&gt;Los caracteres no se corresponden.&lt;/div&gt;";
    } else {
      /*DO STUFF*/
    }
  }
  </code></pre>
  
  <p>And in other file with the name <code>captcha.php</code> i have the code <a href="/questions/tagged/php" class="post-tag" title="show questions tagged &#39;php&#39;" rel="tag">php</a>for generate the image:</p>
  
  <pre><code>header("Content-type: image/png");
  $string = "abcdefghijklmnopqrstuvwxyz0123456789";
  for ($i = 0; $i &lt; 5; $i++) {
    $pos = rand(0, 36);
    $str. = $string {
      $pos
    };
  }
  $img_handle = ImageCreate(60, 22) or die("Es imposible crear la imagen");
  $back_color = ImageColorAllocate($img_handle, 102, 102, 153);
  $txt_color = ImageColorAllocate($img_handle, 255, 255, 255);
  ImageString($img_handle, 31, 5, 0, $str, $txt_color);
  Imagepng($img_handle);
  session_start();
  $_SESSION['img_number'] = $str;
  </code></pre>
  
  <p>This give a image broken showing the alt from <code>img</code> <code>"Numeros aleatorios"</code>, so that tell me the <code>file.php</code> is calling fine the <code>img</code> but the code for generated is not working, any help is gratefull :D thanks.</p>