2011-02-16 147 views
-1

我有一个非常恼人的问题。我有一个验证码系统,可以在我的本地网络设置上使用xammp工作,但它不适用于我的远程Linux机器。我有一个techacha captcha.php文件以某种方式重新加载,但我试图删除我的谷歌分析JavaScript,但它仍然无法正常工作。captcha在本地工作,但不在服务器上!

这里是我的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 

captcha.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']; 

} 

局部当我点击测试I示出了图像中的代码,通过captcha.php生成。但在服务器上,它显示一个随机数字。这怎么可能?如果我发现什么更

+2

仅从查看代码很难调试。这需要一些实时调试:表单变量是否传输,会话变量是否设置等。 – 2011-02-16 11:22:26

+0

也请更清楚地定义什么不起作用。 – 2011-02-16 11:27:09

回答

0

检查是否已安装在主机上GD我将更新我的职务。

<?php 
phpinfo(); 
?> 

phpinfo()会告诉你。

检查一节名为“GD”,如果它不存在,你无法创建图像。

1

我固定它:不要理解错误,但意识到captcha.php文件被加载并以某种方式改变了会话变量。所以我说这验证码

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

,我删除了所有

unset($_SESSION['security_code']) 

现在的图像代码和会话代码保持不变,如果会话代码设置。这可能是一个安全风险,因为用户可以强制验证码,但我不认为用户会为此打破安全。

0

嘿我有同样的问题,但我已经解决了我的问题。我的代码不同,但有同样的问题。我已将验证码生成代码放入验证码文件夹中,此时验证码不匹配。但是,当我从该文件夹中删除我的整个代码,并放在根文件夹中的所有代码它的工作原理是fine.May这将帮助你......

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

相关问题