Ich benutze Apache 2.4 Server auf meinem Laptop unter Windows 10. Ich habe ein Problem mit einem Stück PHP-Code, der zufällige Zahlen für Benutzer zum Tippen zeigen soll, so dass wir das wissen Benutzer ist kein Roboter. Unten ist ein Bild zeigt, was ich rede: The numbers have yellow background is what I'm referring.Apache "localhost ist derzeit nicht in der Lage, diese Anfrage zu bearbeiten." php Anfrage
So wird der Code, den ich für die Erzeugung diese Zahl haben wie folgt:
<?php
/**
USAGE:
\t <img alt="" rel="nofollow,noindex" width="50" height="18" src="php/captcha.php" />
\t $_SESSION['captcha'] - use it in your script.
\t Supported link:
\t \t util/captcha.php?w=100&h=50&s=30&bgcolor=ffffff&txtcolor=000000
**/
\t session_start();
\t @ini_set('display_errors', 0);
\t @ini_set('track_errors', 0);
\t header('Cache-Control: no-cache');
\t header('Pragma: no-cache');
/** **********************************
@RANDOM GENERATORS [LN, N, L]
/** ******************************* **/
function random($length=6,$type=null) { // null = letters+numbers, L = letters, N = numbers
\t \t switch($type) {
\t \t \t case 'N' : \t $chars = ''; \t \t \t \t \t \t \t \t break;
\t \t \t case 'L' : \t $chars = 'abcdefghijklmnopqrstuvwxyz'; \t \t \t \t break;
\t \t \t default : \t $chars = 'abcdefghijklmnopqrstuvwxyz'; \t break;
\t \t }
\t \t $numChars = strlen($chars); $string = '';
for ($i = 0; $i < $length; $i++) { $string .= substr($chars, rand(1, $numChars) - 1, 1); }
\t \t unset($chars);
\t \t return $string;
\t }
/** **********************************
@_GET shortcut and protect
/** ******************************* **/
\t function _getVar($var) {
\t \t if(isset($_GET[$var])) {
\t \t \t return trim($_GET[$var]);
\t \t } else { return null; }
\t }
/** **********************************
@CAPTCHA
/** ******************************* **/
\t // Put the code in session to use in script
\t if(_getVar('c') != '')
\t \t $c = (int) _getVar('c');
\t else
\t \t $c = 6;
\t $mycode = random($c,'N');
\t
\t $_SESSION['captcha'] = $mycode;
\t // Image Size from a specified dimensions
\t $w = (int) _getVar('w'); if($w == '') $w = 60; // width
\t $h = (int) _getVar('h'); if($h == '') $h = 18; // height
\t $s = (int) _getVar('s'); if($s == '') $s = 5; // font size [5 max.]
\t $bgcolor = _getVar('bgcolor'); if($bgcolor == '') $bgcolor = 'ffffff'; // background color [ffffff default]
\t $txtcolor = _getVar('txtcolor'); if($txtcolor == '') $txtcolor = '000000'; // text color [000000 default]
\t // convert color to R G B
\t // [from ffffff to ff ff ff]
\t $bgcol \t = sscanf($bgcolor, '%2x%2x%2x');
\t $txtcol \t = sscanf($txtcolor, '%2x%2x%2x');
\t // Create image
\t $code = $_SESSION['captcha'];
\t $image = imagecreate($w, $h); \t \t \t \t \t \t \t \t \t \t \t // image size [50x18 default]
\t $bgcol = imagecolorallocate($image, $bgcol[0], $bgcol[1], $bgcol[2]); \t // background color
\t $txcol = imagecolorallocate($image, $txtcol[0], $txtcol[1], $txtcol[2]); // text color
\t $strn2 = imagestring($image, $s, 0, 0, $code, $txcol); \t \t \t \t \t // text size [4 default]
\t header('Content-Type: image/jpeg');
// imagepng($image); // make sure --with-png-dir is set
\t imagejpeg($image);
\t imagedestroy($image);
?>
Als ich das laufen Code auf Apache, bekomme ich immer
"Die Localhost-Seite funktioniert nicht. Localhost ist derzeit nicht in der Lage, diese Anfrage zu behandeln. HTTP FEHLER 500 "
dieser Fehler. Ich bin mir bewusst, dass dies ein Serverfehler ist, aber es läuft OK mit meinem Mac OX-Betriebssystem, das Apache vorinstalliert hat. Aber dieser Code bekommt den obigen Fehler, wenn ich Windows 10 benutze, auf dem ich Apache und PHP wie auf Youtube angewiesen installiert habe.
Kann mir jemand helfen ?? Danke im Voraus!
Können Sie den Apache-Fehlerprotokoll schreiben? (Nur die relevanten Bits) – Pete
Das ist es: "[: Fehler] [Pid 3972: Tid 1004] [Client :: 1: 53340] PHP Schwerwiegender Fehler: Uncaught Fehler: Aufruf zu undefinierter Funktion imagecreate() in C: \ apache \\ htdocs \\ captcha.php: 72 \ nStack-Trace: \ n # 0 {main} \ n geworfen in C: \\ apache \\ htdocs \\ captcha.php in Zeile 72, Referer: http: // localhost/" – DawnZHANG
Versuchen Sie, die GD-Erweiterung zu installieren. Siehe http://stackoverflow.com/questions/3106991/fatal-error-call-to-undefined-function-imagecreate. – Pete