Apache“本地主机”目前无法处理此请求.php请求


Apache "localhost is currently unable to handle this request." php request

我在Windows 10下运行的笔记本电脑上使用Apache 2.4服务器。我有一个问题,运行一块php代码应该显示随机数的用户点击,这样我们就知道,这个用户不是一个机器人。下面的图片显示了我所说的:我指的是黄色背景的数字。

因此,生成这些数字的代码如下所示:

<?php
/**
    USAGE:
	<img alt="" rel="nofollow,noindex" width="50" height="18" src="php/captcha.php" />
	$_SESSION['captcha']  - use it in your script.
	Supported link:
		util/captcha.php?w=100&amp;h=50&amp;s=30&amp;bgcolor=ffffff&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 < $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);
?>

当我在Apache上运行这段代码时,我总是得到

"本地主机页面不工作。本地主机目前无法处理此请求。HTTP ERROR 500"

这个错误。我知道这是一个服务器错误,但使用预装Apache的Mac OX操作系统运行正常。但是,如果我使用Windows 10,我已经按照Youtube上的指示安装了Apache和PHP,则此代码会出现上述错误。

有人能帮忙吗??提前感谢!

这是告诉您Apache无法找到本机错误页500。PHP代码中有错误,将display_errors改为1然后在error_reporting(-1);

旁边加上这个