Sunday, 15 January 2012

class - PHP Static var not working -



class - PHP Static var not working -

i'm working on captcha class , i'm done, there 1 thing doesn't work

in file set form, start line:

include 'captcha.php'; $captcha = captcha::trycaptcha(2,4,'#000', '#ffffff');

and captch construct:

static $do_generate = true; function __construct($aantal_letters = 2, $aantal_cijfers = 4, $voorgrond = '#000000', $achtergond = '#ffffff') { session_start(); if (self::$do_generate == true) { $letters = substr(str_shuffle('abcdeghjklmnpqrstuvwxyz'),0 ,$aantal_letters); $cijfers = substr(str_shuffle('23456789'),0 ,$aantal_cijfers); $imgbreed = 18 * ($aantal_letters + $aantal_cijfers); $_session['imgbreed'] = $imgbreed; $_session['captcha'] = $letters . $cijfers; $_session['voorgrond'] = $this->hex2rgb($voorgrond); $_session['achtergond'] = $this->hex2rgb($achtergond); } }

so in other words set stuff in session if static var $do_generate == true

so when post form, captcha getting checked procesor.php

like this:

if (captcha::captcha_uitkomst() == true) { echo "great"; } else { echo "wrong";

}

and captcha function checks etered captcha code:

static function captcha_uitkomst() { if (strcmp($_session['captcha'], strtoupper(str_replace(' ', '', $_post['captcha-invoer']))) == 0) { homecoming true; } else { echo "test"; self::$do_generate = false; homecoming false; } }

if come in right captcha code, it's good, works echo great. if wrong echo wrong,

perfect, but.... when go form (hit backspace 1 history back) come in right captcha, regenerates new captcha.

in class: captcha_uitkomst see made self::do_generate false , echo 'test' works when it's false, (just checking)

what doing wrong

when nail "back", page reloaded. new captcha.

the premise of question fundamentally flawed, have randomly assumed shouldn't happen, whereas in reality entirely design.

it wouldn't effective captcha if repeatedly wrong go , seek again; bot start brute forcing and learning experience.

php class static

No comments:

Post a Comment