Apache“localhost当前无法处理该请求。” PHP请求 [英] Apache "localhost is currently unable to handle this request." php request

查看:1194
本文介绍了Apache“localhost当前无法处理该请求。” PHP请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在运行Windows 10的笔记本电脑上使用Apache 2.4服务器。我遇到了一个运行一段php代码的问题,该代码应该显示随机数字供用户使用,以便我们知道该用户不是机器人。下面是一张图片显示了我在说什么:
数字有黄色背景是什么我指的是。



所以,我用于生成这些数字的代码如下所示:



<?php / **用法:< img alt = =nofollow,noindexwidth = 50height =18src =php / captcha.php/> $ _SESSION ['captcha'] - 在脚本中使用它。支持的链接:util / captcha.php?w = 100& amp; h = 50& s = 30& amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; @ini_set('display_errors',0); @ini_set('track_errors',0);头('Cache-Control:no-cache');标题('Pragma:no-cache'); / ** ********************************** @RANDOM GENERATORS [LN,N,L] / ** ******************************* ** / function random($ length = 6,$ type = null){// null =字母+数字,L =字母,N =数字开关($ type){case'N':$ chars ='0123456789';打破;情况'L':$ chars ='abcdefghijklmnopqrstuvwxyz';打破;默认:$ chars ='abcdefghijklmnopqrstuvwxyz0123456789';打破; } $ numChars = strlen($ chars); $ string =''; for($ i = 0; $ i <$ length; $ i ++){$ string。= substr($ chars,rand(1,$ numChars)-1,1); }未设置($字符);返回$ string; } / ** ********************************** @_GET快捷方式并保护/ ** **** *************************** ** / function _getVar($ var){if(isset($ _ GET [$ var])){返回trim($ _ GET [$ var]); } else {return null; }} / ** ********************************** @CAPTCHA / ** ****** ************************* ** // //将代码放入会话中以便在脚本中使用if(_getVar('c')!=' ')$ c =(int)_getVar('c'); else $ c = 6; $ mycode = random($ c,'N'); $ _SESSION ['captcha'] = $ mycode; //指定尺寸的图片大小$ 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'; //背景颜色[ffffff默认值] $ txtcolor = _getVar('txtcolor'); if($ txtcolor =='')$ txtcolor ='000000'; // text color [000000 default] //将颜色转换为R G B // [从ffffff到ff ff ff] $ bgcol = sscanf($ bgcolor,'%2x%2x%2x'); $ txtcol = sscanf($ txtcolor,'%2x%2x%2x'); //创建图片$ code = $ _SESSION ['captcha']; $ image = imagecreate($ w,$ h); //图像大小[默认为50x18] $ bgcol = imagecolorallocate($ image,$ bgcol [0],$ bgcol [1],$ bgcol [2]); //背景颜色$ txcol = imagecolorallocate($ image,$ txtcol [0],$ txtcol [1],$ txtcol [2]); //文字颜色$ strn2 = imagestring($ image,$ s,0,0,$ code,$ txcol); //文本大小[默认为4] header('Content-Type:image / jpeg'); // imagepng($ image); //确保--with-png-dir被设置为imagejpeg($ image); imagedestroy($ image);?>

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



本地主机页面不工作
localhost当前无法处理这个请求
HTTP ERROR 500



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



任何人都可以帮忙吗?提前致谢!

解决方案

这就是告诉你,Apache不能找到本地错误页面500.你的PHP代码有错误,将 display_errors 更改为1并将其添加到 error_reporting(-1);


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: The numbers have yellow background is what I'm referring.

So, the code that I have for generating these number is as follows:

<?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);

?>

When I run this code on Apache, I always get

"The localhost page isn’t working. localhost is currently unable to handle this request. HTTP ERROR 500"

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.

Can anyone help?? Thanks in advance!

解决方案

That is telling you that Apache cant find native error page 500. You have an error in your PHP code, change display_errors to 1 and add this next to that error_reporting(-1);

这篇关于Apache“localhost当前无法处理该请求。” PHP请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆