Welcome Guest, Not a member yet? Register   Sign In
Becoming white empty page with captcha
#1

[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:
&lt;?php
if ($this->session->flashdata('subscribe_msg')){
echo "<div class='message'>";
echo $this->session->flashdata('subscribe_msg');
echo "</div>";
}
?&gt;

&lt;?php foreach($daten as $comments){?&gt;
&lt;?=$comments['name']?&gt;
&lt;?=$comments['date']?&gt;
&lt;?=$comments['comment']?&gt;


&lt;?php }?&gt;


&lt;?php echo form_open('welcome/subscribe'); ?&gt;
&lt;?php echo form_fieldset('Subscribe To Our Guestbook'); ?&gt;

<p>Name</p>

&lt;input type="text" name="name" id="name" value="&lt;?php echo set_value('name'); ?&gt;" size="40"&gt;&lt;/input>
&lt;input type="hidden" name="date" id="date" value="&lt;?php echo set_value('date(d-m-Y)');?&gt;" size="40"&gt;&lt;input/>
Email

&lt;input type="text" name="email" id="email" value="&lt;?php echo set_value('email'); ?&gt;" size="40"&gt;&lt;/input>
&lt;input type="text" name="comment" id="comment" value="&lt;?php echo set_value('comment'); ?&gt;" size="300"&gt;&lt;input/>
Are you human?

&lt;?php echo $cap_img;?&gt;

&lt;input type="text" name="captcha" value="" size="40" /&gt;

<div>&lt;input type="submit" value="Subscribe" /&gt;&lt;/div>
&lt;?php echo form_fieldset_close(); ?&gt;
&lt;?php form_close();?&gt;


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
#2

[eluser]LuckyFella73[/eluser]
I just had a quick look at your code - try to adjust this part:
Code:
function makeCaptcha()
{
$vals = array(
  'img_path' => 'captcha/',
  'img_url' => base_url().'captcha/', // CHANGE HERE
  'img_width' => 200, // width
  'img_height' => 60, // height
  'captchafont-size' => 30,
  'font_path'    => base_url().'fonts/VeraBd.ttf', // CHANGE HERE
  'expiration' => 7200 ,
);
// ...
}

You placed the "base_url()" inside single quotes - that can't work.
Don't if that is all but at least it's a start Wink
#3

[eluser]jonnyG[/eluser]
cheers1 no its definitly not the prob!
#4

[eluser]Aken[/eluser]
Blank white page usually means a fatal PHP error, but you have error displaying turned off. Check your error reporting settings both in your app and through php.ini - turn them on during development, turn them off in production.
#5

[eluser]jonnyG[/eluser]
[30-Mar-2012 18:46:38] PHP Fatal error: Call to undefined function createCaptcha() in /Library/WebServer/Documents/hallo/application/controllers/welcome.php on line 71

I guess the problem is that the used captcha version is not compatibel with the new captcha version from codeigniter.. possible or?! what you guess?

but actually thats bullshit because it already worked! so there must be something different!
#6

[eluser]pbflash[/eluser]
You're not loading the captcha plugin. In the tutorial it is loaded in the make_captcha function.
#7

[eluser]jonnyG[/eluser]
$autoload['helper'] = array('url', 'form', 'captcha');

Wink
#8

[eluser]jonnyG[/eluser]
SOLVED! Smile




Theme © iAndrew 2016 - Forum software by © MyBB