title: Apache "localhost is currently unable to handle this request." php request
body: <p>I'm using Apache 2.4 server on my laptop running under Windows 10. I’m having a problem running a piece of php code which is supposed to show random numbers for users to tap in, so that we know that this user is not a robot. Below is a picture shows what I’m talking about:
  <a href="http://i.stack.imgur.com/6Rq3s.png" rel="nofollow">The numbers have yellow background is what I'm referring.</a></p>
  
  <p>So, the code that I have for generating these number is as follows:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php
  /**
      USAGE:
   &lt;img alt="" rel="nofollow,noindex" width="50" height="18" src="php/captcha.php" /&gt;
   $_SESSION['captcha']  - use it in your script.
  
   Supported link:
    util/captcha.php?w=100&amp;amp;h=50&amp;amp;s=30&amp;amp;bgcolor=ffffff&amp;amp;txtcolor=000000
  **/
   session_start();
   @ini_set('display_errors', 0);
   @ini_set('track_errors', 0);
  
   header('Cache-Control: no-cache');
   header('Pragma: no-cache');
  
  
  /** ********************************** 
   @RANDOM GENERATORS [LN, N, L]
  /** ******************************* **/
      function random($length=6,$type=null) { // null = letters+numbers, L = letters, N = numbers
  
    switch($type) {
     case 'N' : $chars = '0123456789';         break;
     case 'L' : $chars = 'abcdefghijklmnopqrstuvwxyz';     break;
     default  : $chars = 'abcdefghijklmnopqrstuvwxyz0123456789';  break;
    }
  
    $numChars = strlen($chars); $string = '';
          for ($i = 0; $i &lt; $length; $i++) { $string .= substr($chars, rand(1, $numChars) - 1, 1); }
    unset($chars);
    return $string; 
   }
  
  
  /** ********************************** 
   @_GET shortcut and protect
  /** ******************************* **/
   function _getVar($var) {
    if(isset($_GET[$var])) {
     return trim($_GET[$var]);
    } else { return null; }
   }
  
  
  /** ********************************** 
   @CAPTCHA
  /** ******************************* **/
   // Put the code in session to use in script
   if(_getVar('c') != '') 
    $c = (int) _getVar('c'); 
   else 
    $c = 6;
   $mycode = random($c,'N');
   
   $_SESSION['captcha'] = $mycode;
  
   // Image Size from a specified dimensions
   $w =  (int) _getVar('w'); if($w == '') $w = 60; // width
   $h =  (int) _getVar('h'); if($h == '') $h = 18; // height
   $s =  (int) _getVar('s'); if($s == '') $s = 5; // font size [5 max.]
   $bgcolor  = _getVar('bgcolor');  if($bgcolor == '')  $bgcolor   = 'ffffff'; // background color [ffffff default]
   $txtcolor = _getVar('txtcolor'); if($txtcolor == '') $txtcolor  = '000000'; // text color [000000 default]
  
   // convert color to R  G  B 
   // [from ffffff to  ff ff ff]
   $bgcol   = sscanf($bgcolor,  '%2x%2x%2x');
   $txtcol  = sscanf($txtcolor, '%2x%2x%2x');
   // Create image
   $code  = $_SESSION['captcha'];
   $image = imagecreate($w, $h);            // image size [50x18 default]
   $bgcol = imagecolorallocate($image, $bgcol[0], $bgcol[1],  $bgcol[2]);  // background color
   $txcol = imagecolorallocate($image, $txtcol[0], $txtcol[1], $txtcol[2]); // text color
   $strn2 = imagestring($image, $s, 0, 0, $code, $txcol);     // text size [4 default]
   header('Content-Type: image/jpeg');
  
  //    imagepng($image);  // make sure --with-png-dir is set
   imagejpeg($image);
   imagedestroy($image);
  
  ?&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>When I run this code on Apache, I always get </p>
  
  <p>"The localhost page isn’t working.
  localhost is currently unable to handle this request.
  HTTP ERROR 500"</p>
  
  <p>this error. I'm aware this is a server error but it runs OK using my Mac OX operating system which has Apache pre-installed. But this code get the above error on if I use Windows 10 which I have Apache and PHP installed as instructed on Youtube.</p>
  
  <p>Can anyone help?? Thanks in advance!</p>