"We are back" « oc.at

PHP: Session-Problem

aNtraXx 02.11.2006 - 09:05 940 2
Posts

aNtraXx

trailer park king
Avatar
Registered: Apr 2002
Location: Linz
Posts: 6906
Hallo allerseits!
Hab ein kleines Problem mit Sessions in PHP.

Ich habe ein Formular, welches ich vor Spam schützen will. Und zwar mit so einem Bild, welches von einem Skript generiert wird und wo man dann diese Zahl als Sicherheitscode eingeben muss. Genau diese Zahl aus dem Bild soll dann bei der Bilderstellung in eine Sessionvariable geschrieben werden um diese dann vergleichen zu können.

Ich habe also im Formular folgenden Aufruf:

Code:
<IMG SRC="http://www.ttg.at/formcheck_captcha/captcha.php">

Im Formular ist die Sessionvariable "captcha_code" bereits vorhanden.

Das PHP-Skript schaut wie folgt aus:
Code:
<?php
//Select size of image
$size_x = "150";
$size_y = "100";

//generate random string
$code = mt_rand("100000","999999");

//store captcha code in session vars
session_start();
$_SESSION["captcha_code"] = $code;

//create image to play with
$image = imageCreate($size_x,$size_y);


//add content to image
//------------------------------------------------------


//make background white - first colour allocated is background
$background = imageColorAllocate($image,255,255,255);



//select grey content number
$text_number1 = mt_rand("0","150");
$text_number2 = mt_rand("0","150");
$text_number3 = mt_rand("0","150");

//allocate colours
$white = imageColorAllocate($image,255,255,255);
$black = imageColorAllocate($image,0,0,0);
$text  = imageColorAllocate($image,$text_number1,$text_number2,$text_number3);



//get number of dots to draw
$total_dots = ($size_x * $size_y)/15;

//draw many many dots that are the same colour as the text
for($counter = 0; $counter < $total_dots; $counter++) {
  //get positions for dot
  $pos_x = mt_rand("0",$size_x);
  $pos_y = mt_rand("0",$size_y);

  //draw dot
  imageSetPixel($image,$pos_x,$pos_y,$text);
};



//draw border
imageRectangle($image,0,0,$size_x-1,$size_y-1,$black);



//get coordinates of position for string
//on the font 5 size, each char is 15 pixels high by 9 pixels wide
//with 6 digits at a width of 9, the code is 54 pixels wide
$pos_x = bcmod($code,$size_x-60) +3;
$pos_y = bcmod($code,$size_y-15);

//draw random number
imageString($image,  5,  $pos_x,  $pos_y,  $code,  $text);


//------------------------------------------------------
//end add content to image


//send browser headers
header("Content-Type: image/jpeg");


//send image to browser
echo imageJPEG($image);

//destroy image
imageDestroy($image);
?>


Das Bild wird erstellt, jedoch wird die Session nicht angerührt. Hab schon einiges herumprobiert/gespielt. Wenn ich das PHP-File nur als Include angebe, dann geht das mit der Session zwar, jedoch dauert es ewig, bis die Seite geladen wird ~ 5mins.

Hat irgendjemand eine Idee?

tia, Bernhard

kleinerChemiker

Here to stay
Avatar
Registered: Feb 2002
Location: Wien
Posts: 4331
wenn du keine cookies aktivert hast, wird mit <IMG SRC="http://www.ttg.at/formcheck_captcha/captcha.php"> die sid nicht weitergeleitet.

aNtraXx

trailer park king
Avatar
Registered: Apr 2002
Location: Linz
Posts: 6906
Hmm... Das hab ich mir auch schon gedacht. Allerdings funktioniert es plötzlich aus heiterem Himmel :confused:

Die Cookies im Browser waren jedoch aktiviert.
Kontakt | Unser Forum | Über overclockers.at | Impressum | Datenschutz