[eluser]jonnyG[/eluser]
hola,
well I integrated
http://www.cecilieokada.com/blog/web-dev...in-part-2/
this captcha to my site.
I don't wanna use it as newsletter just as guestbook but that really doesnt matter.
The problem is that when I go on my page.. a white page shows up!
The Controller:
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Welcome extends CI_Controller {
function __construct(){
parent::__construct();
session_start();
$this->output->enable_profiler(FALSE);
}
public function index()
{
$captcha_result = '';
$data['cap_img'] = $this->makeCaptcha();
$data['daten'] = $this->guestbook->getAllSubscribers();
$this->load->view('home', $data);
}
public function subscribe(){
/**
* form_validation
*/
$this->form_validation->set_rules('name', 'Name', 'required');
$this->form_validation->set_rules('comment', 'Comment', 'required');
$this->form_validation->set_rules('captcha', 'Captcha', 'required');
if ( $this -> checkCaptcha() ) {
if ($this->form_validation->run() == FALSE)
{
$this->session->set_flashdata('subscribe_msg', 'All fields are required . Please try again!');
redirect('welcome/index');
}
else
{
$name = $this->input->post('name');
$email = $this->input->post('email');
$comment = $this->input->post('comment');
$date = $this->input->post('date');
$this->guestbook->createSubscriber($name, $email, $comment, $date);
$this->session->set_flashdata('subscribe_msg', 'Thanks for subscribing!');
redirect('welcome/index','refresh');
}
}else {
$this->session->set_flashdata('subscribe_msg', 'Enter captcha . Please try again!');
redirect('welcome/index');
}
}
/**
* For captcha
*/
function makeCaptcha()
{
$vals = array(
'img_path' => 'captcha/', // PATH for captcha ( *Must mkdir (htdocs)/captcha )
'img_url' => 'base_url()./captcha/', // URL for captcha img
'img_width' => 200, // width
'img_height' => 60, // height
'captchafont-size' => 30,
'font_path' => 'base_url()./fonts/VeraBd.ttf',
'expiration' => 7200 ,
);
// Create captcha
$cap = createCaptcha( $vals );
// Write to DB
if ( $cap ) {
$data = array(
'captcha_id' => '',
'captcha_time' => $cap['time'],
'ip_address' => $this -> input -> ip_address(),
'word' => $cap['word'] ,
);
$query = $this -> db -> insert_string( 'captcha', $data );
$this -> db -> query( $query );
}else {
return "Umm captcha not work" ;
}
return $cap['image'] ;
}
function checkCaptcha()
{
// Delete old data ( 2hours)
$expiration = time()-7200;
$sql = "DELETE FROM captcha WHERE captcha_time < ? ";
$binds = array($expiration);
$query = $this->db->query($sql, $binds);
//checking input
$sql = "SELECT COUNT(*) AS count FROM captcha WHERE word = ? AND ip_address = ? AND captcha_time > ?";
$binds = array($_POST['captcha'], $this->input->ip_address(), $expiration);
$query = $this->db->query($sql, $binds);
$row = $query->row();
if ( $row -> count > 0 )
{
return true;
}
return false;
}
}
Code:
<?php
if ($this->session->flashdata('subscribe_msg')){
echo "<div class='message'>";
echo $this->session->flashdata('subscribe_msg');
echo "</div>";
}
?>
<?php foreach($daten as $comments){?>
<?=$comments['name']?>
<?=$comments['date']?>
<?=$comments['comment']?>
<?php }?>
<?php echo form_open('welcome/subscribe'); ?>
<?php echo form_fieldset('Subscribe To Our Guestbook'); ?>
<p>Name</p>
<input type="text" name="name" id="name" value="<?php echo set_value('name'); ?>" size="40"></input>
<input type="hidden" name="date" id="date" value="<?php echo set_value('date(d-m-Y)');?>" size="40"><input/>
Email
<input type="text" name="email" id="email" value="<?php echo set_value('email'); ?>" size="40"></input>
<input type="text" name="comment" id="comment" value="<?php echo set_value('comment'); ?>" size="300"><input/>
Are you human?
<?php echo $cap_img;?>
<input type="text" name="captcha" value="" size="40" />
<div><input type="submit" value="Subscribe" /></div>
<?php echo form_fieldset_close(); ?>
<?php form_close();?>
The model has just a db get function and a post function..! The mysql-code is workin!
anybody an idea why I become a white page with nothing on it?
when I delete the first 3 lines in the index function the pages shows up!
So there must be something! But I just dont get it!
cheers for helpin!
jonny