Weiterleitung nach Sichheitskontrolle!

Okay, habe meinen Fehler gefunden! es muß so heißen:

PHP:
<?php 
    session_start(); 

    require_once 'class.captcha.php'; 

    if( !isset($_GET[session_name()]) ) { 
        $_GET[session_name()] = session_id(); 
    } 
    $captcha = new captcha($_GET[session_name()], 'tmp/'); 

    if( isset($_GET['action']) && $_GET['action']=='verify' ) { 
        if( $my_captcha->verify($_POST['password']) ) { 
            include 'gb.php'; 
        } else { 
            header('HTTP/1.1 400 Bad Request', true); 
        } 
    }; 

	$pic_url = $my_captcha -> get_pic( 4 );

?>

Nun habe ich nur ein Problem: Die Funktion get_pic, die aufgerufen werden soll liefert mir folgenden Fehler:

Fatal error: Call to a member function on a non-object in /home/boogicby/www.boogie-palace.com/guestbook/submit.php on line 19

Jetzt weiß ich schon, das es heißen kann, das die Funktion nicht gefunden wird, sie ist aber da. Gibt es noch eine andere Interpretationsmöglichkeit?

Oder ist am Funktionsaufruf:
PHP:
$pic_url = $my_captcha->get_pic( 4 );
etwas falsch?
 
Zuletzt bearbeitet:
Wo wird denn $my_captcha initialisiert ? Du erstellst vorher nur eine Instanz namens $captcha... In den vorherigen Posts war das immer die gleiche Instanz ?!
 
Das ist die class dazu:

PHP:
 <?php

	/*
		Jax Captcha Class v1.o1 - Copyright (c) 2005, Andreas John aka Jack (tR)
		This program and it's moduls are Open Source in terms of General Public License (GPL) v2.0
	
		class.captcha.php 		(captcha class module)
		
		Last modification: 2005-09-05
	*/
	
	class captcha
	{
		var $session_key = null;
		var $temp_dir    = null;
		var $width       = 170;
		var $height      = 60;
		var $jpg_quality = 15;
		
		
		/**
		 * Constructor - Initializes Captcha class!
		 *
		 * @param string $session_key
		 * @param string $temp_dir
		 * @return captcha
		 */
		function captcha( $session_key, $temp_dir )
		{
			$this->session_key = $session_key;
			$this->temp_dir    = $temp_dir;
		}
		
				
		/**
		 * Generates Image file for captcha
		 *
		 * @param string $location
		 * @param string $char_seq
		 * @return unknown
		 */
		function _generate_image( $location, $char_seq )
		{
			$num_chars = strlen($char_seq);
			
			$img = imagecreatetruecolor( $this->width, $this->height );
			imagealphablending($img, 1);
			imagecolortransparent( $img );
			
			// generate background of randomly built ellipses
			for ($i=1; $i<=200; $i++)
			{
				$r = round( rand( 0, 100 ) );
				$g = round( rand( 0, 100 ) );
				$b = round( rand( 0, 100 ) );
				$color = imagecolorallocate( $img, $r, $g, $b );
				imagefilledellipse( $img,round(rand(0,$this->width)), round(rand(0,$this->height)), round(rand(0,$this->width/16)), round(rand(0,$this->height/4)), $color );	
			}
			
			$start_x = round($this->width / $num_chars);
			$max_font_size = $start_x;
			$start_x = round(0.5*$start_x);
			$max_x_ofs = round($max_font_size*0.9);
			
			// set each letter with random angle, size and color
			for ($i=0;$i<=$num_chars;$i++)
			{
				$r = round( rand( 127, 255 ) );
				$g = round( rand( 127, 255 ) );
				$b = round( rand( 127, 255 ) );
				$y_pos = ($this->height/2)+round( rand( 5, 20 ) );
				
				$fontsize = round( rand( 18, $max_font_size) );
				$color = imagecolorallocate( $img, $r, $g, $b);
				$presign = round( rand( 0, 1 ) );
				$angle = round( rand( 0, 25 ) );
				if ($presign==true) $angle = -1*$angle;
				
				ImageTTFText( $img, $fontsize, $angle, $start_x+$i*$max_x_ofs, $y_pos, $color, '/home/boogicby/www.boogie-palace.com/guestbook/amrtypebf', substr($char_seq,$i,1) );
			}
			
			// create image file
			imagejpeg( $img, $location, $this->jpg_quality );
			flush();
			imagedestroy( $img );
				
			return true;
		}
		
		
		/**
		 * Returns name of the new generated captcha image file
		 *
		 * @param unknown_type $num_chars
		 * @return unknown
		 */
		function get_pic( $num_chars=8 )
		{
			// define characters of which the captcha can consist
			$alphabet = array( 
				'a','b','c','d','e','f','g','h','i','j','k','l','m',
				'n','o','p','q','r','s','t','u','v','w','x','y','z',
				'1','2','3','4','5','6','7','8','9','0' );
				
			$max = sizeof( $alphabet );
			
			// generate random string
			$captcha_str = '';
			for ($i=1;$i<=$num_chars;$i++) // from 1..$num_chars
			{
				// choose randomly a character from alphabet and append it to string
				$chosen = rand( 1, $max );
				$captcha_str .= $alphabet[$chosen-1];
			}
			
			// generate a picture file that displays the random string
			if ( $this->_generate_image( $this->temp_dir.'/'.'cap_'.md5( strtolower( $captcha_str )).'.jpg' , $captcha_str ) )
			{
				$fh = fopen( $this->temp_dir.'/'.'cap_'.$this->session_key.'.txt', "w" );
				fputs( $fh, md5( strtolower( $captcha_str ) ) );
				return( md5( strtolower( $captcha_str ) ) );
			}
			else 
			{
				return false;
			}
		}
		
		/**
		 * check hash of password against hash of searched characters
		 *
		 * @param string $char_seq
		 * @return boolean
		 */
		function verify( $char_seq )
		{
			$fh = fopen( $this->temp_dir.'/'.'cap_'.$this->session_key.'.txt', "r" );
			$hash = fgets( $fh );
			
			if (md5(strtolower($char_seq)) == $hash)
				return true;
			else 
				return false;			
		}		
	}


?>

Ergo, fehlt das:
PHP:
$my_captcha = new captcha( $session_code, 'tmp/' );
?
 
Ceppi wollte dich darauf hinweisen, dass die Instanz der Klasse „$captcha“ heißt, du jedoch versuchst mit „$my_captcha“ zu arbeiten.
 
okay, habe den fehler nundoch selbst gefunden! Es tut mir leid, das wir die ganze Zeit an der falschen stelle gegraben haben, aber so muß es richgtig lauten:

PHP:
<?php
	require_once( 'class.captcha.php' );

	if (empty($_GET['session_code'])) 
		{ $session_code = md5(round(rand(0,40000))); } 
	else 
		{ $session_code=$_GET['session_code']; }	
	
	$my_captcha = new captcha( $session_code, 'tmp/' );

	$do = $_GET['do'];
	
	if ($do == 'verify')
	{
		if ($my_captcha->verify( $_POST['password'] ) )
		{
			include('gb.php');
			exit;	
		}
	}

	$pic_url = $my_captcha->get_pic( 4 );

	?>
<html>
<head><title>Eintrag erstellen - Boogie-Palace.com</title>
<style type="text/css">
<!--
.textbox { background: transparent; background-color: White; border: 1px solid #000000; color: #000000; font-family: Verdana, Arial; font-size: x-small; text-align: left; scrollbar-face-color: #CCCCCC; scrollbar-shadow-color: #FFFFFF; scrollbar-highlight-color: #FFFFFF; scrollbar-3dlight-color: #FFFFFF; scrollbar-darkshadow-color: #FFFFFF; scrollbar-track-color: #FFFFFF; scrollbar-arrow-color: #000000 }
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>
<body bgcolor="#336699" text="#FFFFFF" link="#FFFFFF" vlink="#FFFFFF" alink="#FFFFFF">
<?php echo "<form method=\"post\" action=\"$PHP_SELF?do=verify&session_code=".$session_code."\">"; ?>
  <strong><font face="Arial, Helvetica, sans-serif, Comic Sans MS"> <font size="4">Eintrag 
  erstellen</font></font></strong> <br>
  <br>
  <table width="70%" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr> 
    <td width="20%" align="right"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Name:&nbsp; 
      </font></b></td>
    <td> 
        <font face="Verdana, Arial, Helvetica, sans-serif" size="2"><input type="text" name="name" class=textbox></font>
    </td>
  </tr>
  <tr> 
    <td width="20%" align="right"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Email:&nbsp; 
      </font></b></td>
    <td> 
        <font face="Verdana, Arial, Helvetica, sans-serif" size="2"><input type="text" name="email" class=textbox> (freiwillig)</font>
    </td>
  </tr>
  <tr> 
    <td width="20%" align="right"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">ICQ:&nbsp; 
      </font></b></td>
    <td> 
        <font face="Verdana, Arial, Helvetica, sans-serif" size="2"><input type="text" name="icq" class=textbox>  (freiwillig)</font>
    </td>
  </tr>
  <tr> 
    <td width="20%" align="right"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Homepage:&nbsp; 
      </font></b></td>
    <td> 
        <font face="Verdana, Arial, Helvetica, sans-serif" size="2">
        <input name="homepage" type="text" class=textbox>
         (freiwillig, mit http://)</font>
    </td>
  </tr>
  <tr> 
      <td width="20%" align="right" valign="top"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Text:&nbsp; 
        </font></b></td>
    <td> 
        <p><font face="Verdana, Arial, Helvetica, sans-serif" size="2">
          <textarea name="text" cols=50 rows=6 class=textbox></textarea>
          </font> </p>
		<?PHP
		echo "<p><img src=\"captcha_image.php?img=$pic_url\" border=\"1\"><br><br></p>
	   	</td></tr><tr> 
      	<td width=\"20%\" align=\"right\" valign=\"top\"><b><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"2\">Code:&nbsp; 
        </font></b></td>
	    <td> 
        <font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"2\"><input type=\"text\" name=\"password\"></font>
		<br><br></td>";
		?>
  </tr>
  <tr>
    <td width="20%" align="right">&nbsp;

    </td>
    <td>
      <font face="Verdana, Arial, Helvetica, sans-serif" size="2"><input type="submit" name="entry" value="Submit">
        <font size="-1"> [<a href=help.html target="_blank">Hilfe/Help</a>]</font></font> 
      </td>
  </tr>
</table>
</form>
<center>
  <a href="javascript:history.back(1)"><font size="-1" face="Arial, Helvetica, sans-serif, Comic Sans MS">Zurück</font></a>
</center>
</body>
</html>

Der fehler lag in der Übergabe der Variablen! Aber trotzdem danke!
 
Zurück