-1

私は非常に厄介な問題を抱えています。xammp を使用したローカル ネットワーク セットアップで動作するキャプチャ システムがありますが、リモートの Linux ボックスでは動作しません。captcha.php ファイルがどうにかリロードされるというテオリがありますが、Google アナリティクスの JavaScript を削除しようとしましたが、それでも機能しませんでした。

これが私のhtmlです:

<div class="box">
                    <h2>Captcha</h2>
                    <div class="block">
                        <p>Are you human? Type in the text bellow to prove it.</p>  
                        <table><form action="homepage.php" method="post">

                        <tr>
                            <td><img src="captcha.php?width=120&height=40&characters=5" /></td>
                            <td>
                                <label for="security_code">Security Code:</label><input id="security_code" name="security_code" type="text" />
                            </td>
                        </tr>
                        <tr>
                            <td>&nbsp;</td>

                            <td><input type="submit" name="human" value="Submit" /></td>
                        </tr>
                        </form></table>

                    </div>
                </div

キャプチャ.php

<?php
session_start();

/*
* File: CaptchaSecurityImages.php
* Author: Simon Jarvis
* Copyright: 2006 Simon Jarvis
* Date: 03/08/06
* Updated: 07/02/07
* Requirements: PHP 4/5 with GD and FreeType libraries
* Link: http://www.white-hat-web-design.co.uk/articles/php-captcha.php
* 
* This program is free software; you can redistribute it and/or 
* modify it under the terms of the GNU General Public License 
* as published by the Free Software Foundation; either version 2 
* of the License, or (at your option) any later version.
* 
* This program is distributed in the hope that it will be useful, 
* but WITHOUT ANY WARRANTY; without even the implied warranty of 
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
* GNU General Public License for more details: 
* http://www.gnu.org/licenses/gpl.html
*
*/

class CaptchaSecurityImages {

    var $font = 'fonts/monofont.ttf';

    function generateCode($characters) {
        /* list all possible characters, similar looking characters and vowels have been removed */
        $possible = '23456789bcdfghjkmnpqrstvwxyz';
        $code = '';
        $i = 0;
        while ($i < $characters) { 
            $code .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
            $i++;
        }
        return $code;
    }

    function CaptchaSecurityImages($width='120',$height='40',$characters='6') {
        $code = $this->generateCode($characters);
        /* font size will be 75% of the image height */
        $font_size = $height * 0.75;
        $image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream');
        /* set the colours */
        $background_color = imagecolorallocate($image, 255, 255, 255);
        $text_color = imagecolorallocate($image, 20, 40, 100);
        $noise_color = imagecolorallocate($image, 100, 120, 180);
        /* generate random dots in background */
        for( $i=0; $i<($width*$height)/3; $i++ ) {
            imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color);
        }
        /* generate random lines in background */
        for( $i=0; $i<($width*$height)/150; $i++ ) {
            imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color);
        }
        /* create textbox and add text */
        $textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function');
        $x = ($width - $textbox[4])/2;
        $y = ($height - $textbox[5])/2;
        imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code) or die('Error in imagettftext function');
        /* output captcha image to browser */
        header('Content-Type: image/jpeg');
        imagejpeg($image);
        imagedestroy($image);
        $_SESSION['security_code'] = $code;
    }

}

$width = isset($_GET['width']) ? $_GET['width'] : '120';
$height = isset($_GET['height']) ? $_GET['height'] : '40';
$characters = isset($_GET['characters']) && $_GET['characters'] > 1 ? $_GET['characters'] : '6';

$captcha = new CaptchaSecurityImages($width,$height,$characters);

?>

チェック機能の一部:

if( $_SESSION['security_code'] != $code_input ){

    unset($_SESSION['security_code']);
    return 1; 
}

編集:

わかりました、これをhtmlに追加しました:

<input type="submit" name="test" value="test" />

そしてこれをphpに:

if( isset($_POST["test"]) ){

    echo $_SESSION['security_code']; 

}

ローカルでテストをクリックすると、captcha.php によって生成されたコードが画像に表示されます。ただし、サーバー上では、乱数が表示されます..これはどうしてですか? さらに何かわかったら、投稿を更新します

4

4 に答える 4

1

私はそれを修正しました:バグを理解していませんでしたが、captcha.phpファイルがロードされ、セッション変数を何らかの方法で変更したことに気付きました。だから私はこれをキャプチャに追加しました

    if( isset($_SESSION['security_code']) ){
        return $_SESSION['security_code']; 
    }

そして私はすべてを削除しました

unset($_SESSION['security_code'])

これで、セッションコードが設定されている場合、イメージコードとセッションコードは同じままになります。ユーザーはキャプチャをブルートフォースする可能性があるため、これはセキュリティリスクになる可能性がありますが、ユーザーがセキュリティを破るためにそれほど遠くまで行くことはないと思います。

于 2011-02-16T12:31:49.653 に答える
1

ホストに GD がインストールされているかどうかを確認します。

<?php
phpinfo();
?>

phpinfo() が教えてくれます。

「GD」というタイトルのセクションを確認してください。そこにない場合は、イメージを作成できません。

于 2011-02-16T11:24:16.170 に答える
0

この問題は本当に厄介です。幸いなことに、解決策は簡単です。次の場所に移動します。

/wp-config.php

そして、行 (39 程度) を見つけて、この関数呼び出しをコメントアウトします。

// Turn register_globals off.
//wp_unregister_GLOBALS();

Worpress は $_SESSION 変数を強制終了しなくなりました。ところで。サーバーで register_globals をオフにしている場合、Worpress は $_SESSION も有効にします.. 奇妙な :)

WP サポート フォーラムへのクレジットhttp://wordpress.org/support/topic/wp-blog-headerphp-killing-sessions

于 2013-08-24T00:15:44.260 に答える
0

ちょっと私は同じ問題を抱えていますが、私は私の問題を解決しました。私のコードは異なっていましたが、同じ問題があります。キャプチャ コードが一致しない時点で、キャプチャ コード生成コードをキャプチャ フォルダに配置しました。しかし、そのフォルダーからコード全体を削除し、すべてのコードをルートフォルダーに配置すると、正常に機能します。

于 2012-04-11T07:32:17.810 に答える