Session Problem bei shoutbox captcha

Hier können Probleme und alles andere in Deutscher Sprache gelöst werden.
Post Reply
LCD
Posts: 3
Joined: Mon Jul 14, 2008 1:08 pm

Session Problem bei shoutbox captcha

Post by LCD »

Hallo erst mal. :-)
Ich habe mit vor ein paar tagen Serendipity heruntergeladen und "aufgespielt". Da ich die Shoutbox
nutzen möchte, aber keine Lust habe täglich bzw. stündlich Spam zu löschen, habe ich kurzer Hand
das Plugin modifiziert und ein Captcha eingebaut. Obwohl ich kein PHP Profi bin, war dies nicht allzu
schwer.

Im Grunde habe ich nur den original- Quellcode folgendermaßen modifiziert (serendipity_plugin_shoutbox.php):

Code: Select all

if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'fillshoutbox' && $_REQUEST['serendipity']['shouttext'] != '' && $passedCaptchaValidation != false) {
    //schreibs rein...
}
"$passedCaptchaValidation" ergibt sich auf folgendem Code der ebenfalls in der "serendipity_plugin_shoutbox.php" steht:

Code: Select all

if(isset($_SESSION['cpta_bk_spam']) AND $_POST["bk_cpta"] == $_SESSION['cpta_bk_spam']) {
     $passedCaptchaValidation = true;
     unset($_SESSION['cpta_bk_spam']);
} else {
   $passedCaptchaValidation = false;
   unset($_SESSION['cpta_bk_spam']);
}
Klar kann man dies eleganter lösen allerdings will ichs erst mal testen. Danach wird verfeinert.

Im "Form- Bereich" wurde folgendes hinzugefügt:

Code: Select all

<div style="width: 90%; display: inline; text-align: center;">
  <div style="float: left;"><img src="plugins/serendipity_plugin_shoutbox/captcha.php" border="0" alt="" title="" width="84" height="24" /> </div>
  <div style="float: left; text-align: center;">
    <input name="bk_cpta" type="text" style=" width: 70px; font-weight:bold;" alt="" title="" />
  </div>
  <div style="clear: both;"></div>
</div>
Die "captcha.php" ist wohl wie jede andere aufgebaut. :-)


Jetzt zu meinem Problem. Alles funktioniert einwandfrei! Sobald ich mich allerdings auslogge
ist kein Captcha mehr gültig. "$_SESSION['cpta_bk_spam']" ist leer. Also Besucher können
keine Erinträge machen. Woran liegt das? Wie schon erwähnt sind meine PHP skills nicht so prall.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Session Problem bei shoutbox captcha

Post by garvinhicking »

Hi!

Ist für Besucher denn eine Session aktiv bei dir? Macht deine captcha.php vielleicht irgendwas mit der Session?

Eigentlich start s9y sowohl für eingeloggte User als auch für Besucher immer eine Session. Wird ein Session-Cookie denn bei dir auch für besucher ausgeliefert?

Grüße,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
LCD
Posts: 3
Joined: Mon Jul 14, 2008 1:08 pm

Post by LCD »

Session wird für Besucher gestartet und ebenso wird ein Session-Cookie ausgeliefert.
Das macht die captcha.php:

Code: Select all

<?php 

so wohl

/*if (!isset($_SESSION)) {
  session_start();
}*/

als auch

//@session_start();

unset($_SESSION['cpta_bk_spam']); 

   function randomString($len) { 
      function make_seed(){ 
         list($usec , $sec) = explode (' ', microtime()); 
         return (float) $sec + ((float) $usec * 100000); 
   } 
      srand(make_seed());   
      $possible="ABCDEFGHJKLMNPRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789"; 
      $str=""; 
      while(strlen($str)<$len) { 
        $str.=substr($possible,(rand()%(strlen($possible))),1); 
      } 
   return($str); 
   } 

   $text = randomString(5);
   $_SESSION['cpta_bk_spam'] = $text; 
          
   header('Content-type: image/png'); 
   $img = ImageCreateFromPNG('captcha.png');
   $color = ImageColorAllocate($img, 0, 0, 0); 
   $ttf = "XTC.TTF";
   $ttfsize = 12; 
   $angle = rand(0,4); 
   $t_x = rand(5,30); 
   $t_y = 16; 
   imagettftext($img, $ttfsize, $angle, $t_x, $t_y, $color, $ttf, $text); 
   imagepng($img);
   imagedestroy($img);
?>
Ähm...mit folgendem code funktioniert es. Wie gesagt, ich bin kein Profi ;-)

Code: Select all

if(!session_is_registered('cpta_bk_spam'))
{
session_register('cpta_bk_spam');
}
Hier ein Link zur Seite, falls das weiter hilft.
Der Blog ist eben noch im aufbau.
Last edited by LCD on Wed Jul 23, 2008 12:27 am, edited 1 time in total.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

Jupp, ich kann auch als Besucher korrekt was eintragen. Warum ein "session_register" allerdings benötigt werden sollte ist mir schleierhaft. $_SESSION ist ja superglobal, das müsste eigentlich schon klappen...

Grüße,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
LCD
Posts: 3
Joined: Mon Jul 14, 2008 1:08 pm

Post by LCD »

Das verstehe ich auch nicht. :? Vllt liegts ja am Hoster. Von denen hört man die tollsten Dinge. Spätestens wenn der Blog auf dem "richtigen" Host arbeitet weiss ich mehr.

Trotzdem vielen Dank Garvin!
Post Reply