🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.php
Article #230446

captcha a codeigniter

#230446
From: jivanmukta
Date: Mon, 09 Jun 2014 12:24
56 lines
2535 bytes
Ponieważ nie znalazłem biblioteki do captcha w klasach CodeIgnitera zdecydowałem się użyć securimage. Zrobiłem tak (jeszcze nie testowałem):

Plik libraries/Captcha.php zawiera:

<?php
require_once '../thiry_party/securimage/securimage.php';

class Captcha extends Securimage {

// zapamiętaj kod w sesji:
public function saveCodeInSession() {
	$_SESSION['captcha_code'] = $this->code;
}
	
// sprawdź czy poprawnie podano CAPTCHA:
public function validateCaptcha($input) {
	$this->code = $_SESSION['captcha_code'];
  	if (is_string($input) && $this->check($input)) {
		return TRUE;
	}
	$_SESSION['captcha_key_error'] = 'Napis nie pasuje. Spróbuj jeszcze raz.';
	return FALSE;
}

}

Widok zawiera:

	<td>
	Wpisz napis widoczny na obrazku (to jest weryfikacja):<br>
        <input type="text" name="captcha_key" maxlength="8" size="8" style="width: 8ex">
            <?php echo $_SESSION['captcha_key_error']; ?>
	</td>
	<td>
	<img src="captcha.php" alt="">
	</td>

Plik views/captcha.php zawiera:

<?php
session_start();

require_once '../libraries/Captcha.php';

$captcha = new Captcha;
$captcha->saveCodeInSession();
$captcha->show();

Kontroler zawiera:

		$this->load->view('captcha');
                ...
		if ($this->form_validation->run() != FALSE && $this->captcha->validateCaptcha($this->input->post('captcha_key'))) {
...

Proszę o uwagi, bo to moja pierwsza aplikacja w CI.
Technical Details
Message-ID: <d75a460a-f461-42f0-99c7-45ab04b72bb9@googlegroups.com>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!goblin1!goblin.stu.neva.ru!hw13no5804766qab.0!news-out.google.com!q9ni357qaj.0!nntp.google.com!hw13no5804763qab.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Received: by 10.236.101.148 with SMTP id b20mr5795916yhg.46.1402316686556;        Mon, 09 Jun 2014 05:24:46 -0700 (PDT)
X-Received: by 10.140.91.40 with SMTP id y37mr3901qgd.37.1402316686533; Mon, 09 Jun 2014 05:24:46 -0700 (PDT)
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!goblin1!goblin.stu.neva.ru!hw13no5804766qab.0!news-out.google.com!q9ni357qaj.0!nntp.google.com!hw13no5804763qab.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups: pl.comp.lang.php
Date: Mon, 9 Jun 2014 05:24:46 -0700 (PDT)
Complaints-To: groups-abuse@google.com
Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=83.31.3.251; posting-account=Fd8BNwoAAACl8PCi6-fI0bkHGOgt6LMa
NNTP-Posting-Host: 83.31.3.251
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <d75a460a-f461-42f0-99c7-45ab04b72bb9@googlegroups.com>
Subject: captcha a codeigniter
From: jivanmukta@poczta.onet.pl
Injection-Date: Mon, 09 Jun 2014 12:24:46 +0000
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit