title: Comparing user-input CAPTCHA value against expected value stored in session
body: <p>I'm trying to implement a simple captcha into a form I'm building but I've run up against an issue I can't seem to sort out by myself.</p>
  
  <p>I'm using simple code to generate a random number like so ....</p>
  
  <pre><code>$randomnr = rand(1000, 9999);
  $_SESSION['randomnr2'] = md5($randomnr);
  </code></pre>
  
  <p>.... and then some more code to generate an image of the random number and display it on the page. I'm against it for validity like this ....</p>
  
  <pre><code>if (strlen($captcha) !== ($_SESSION['randomnr2'])) { 
      $error['captcha'] = "CAPTCHA error. Please try again";
  }
  </code></pre>
  
  <p>How do I go about checking the value that's been input into the captcha input field against the random number that's stored in the session <code>randomnr2</code>?</p>