Welcome Guest, Not a member yet? Register   Sign In
Captcha Validation
#11

[eluser]0077[/eluser]
@luckyfella73

Thanks for Posting my codes. Anyway if incase I will use CI way of validating captcha would it be possible to validate input data in two ways? in javascript like what I did and in captcha incase?
#12

[eluser]0077[/eluser]
Thanks!
Here's the revision I'd made.. in my controller I added the function that make a captcha as well as validate it..

<?php
session_start();

class Fare_details extends Controller {

function Fare_details()
{
parent::Controller();

$this->load->helper('string');
$this->load->helper('url');
$this->load->database();
$this->load->helper('array');
}

function index()
{
$this->load->model('fare_details_model','', TRUE);

$data['fare_details'] = $this->fare_details_model->get_fare_details();

$captcha_result = '';
$data["cap_img"] = $this -> _make_captcha();
if ( $this -> input -> post( 'submit' ) )
{
if ( $this -> _check_capthca() )
{
$captcha_result = 'Correct Security Code';
}
else
{
$captcha_result = 'Please enter correct Security Code';
}
}

$data["cap_msg"] = $captcha_result;
$this->load->view('fare_details', $data);

}

function _make_captcha()
{
$this -> load -> plugin( 'captcha' );
$vals = array(

'img_path' => './captcha/', // PATH for captcha ( *Must mkdir (htdocs)/captcha )
'img_url' => 'http://localhost/ci_captcha/captcha/', // URL for captcha img
'img_width' => 200, // width
'img_height' => 60, // height
'font_path' => '../system/fonts/2.ttf',
#'font_path' => BASEPATH . 'fonts/sazanami-gothic.ttf', // custom font ( not in Original CI )
'expiration' => 7200 ,
);
// Create captcha
$cap = create_captcha( $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 _check_capthca()
{
// var_dump( $_POST );//debug

// Delete old data ( 2hours)
$expiration = time()-7200 ;

$this -> db -> where( 'captcha_time < ', $expiration );
$this -> db -> delete( 'captcha' );

// var_dump( $this -> db -> last_query() );

// Check input data
$this -> db -> select( 'count(*) as count' );
$this -> db -> where( 'word', $this -> input -> post( 'captcha' ) );
$this -> db -> where( 'ip_address', $this -> input -> ip_address() );
$this -> db -> where( 'captcha_time > ', $expiration );
$query = $this -> db -> get( 'captcha' );
$row = $query -> row();

// var_dump( $this -> db -> last_query() );

if ( $row -> count > 0 ) {
return true;
}
return false;

}

function add_contact_information()
{
$this->load->model('fare_details_model', '', TRUE);

if(!empty($_POST))
{
$id = $this->fare_details_model->add_contact_information(
$this->input->post('card_type'),
$this->input->post('card_number'),
$this->input->post('expiration_date'),
$this->input->post('cvc2_cvv2_code'),
$this->input->post('security_code')
);
}

$result = 'saved';

echo json_encode($result);
}
}
#13

[eluser]0077[/eluser]
Here's my view codes, I do some revision regardig the captcha.. I call the one CI made..

<table border="0" cellpadding="3" cellspacing="0">
<tr>
<td height="25" width="150"><strong>Type of Card</strong></td>
<td width="5">&nbsp;</td>
<td width="200">
<select name="card_type" id="card_type">
<option value="">Select</option>
<option value="Visa">Visa</option>
<option value="Mastercard">Mastercard</option>
</select>
</td>
</tr>
<tr>
<td height="25"><strong>Credit Card Number:</strong></td>
<td>&nbsp;</td>
<td>&lt;input style="width:200px;" type="text" name="card_number"
id="card_number"/&gt;&lt;/td>
</tr>
<tr>
<td height="25"><strong>Expiration Date:</strong></td>
<td>&nbsp;</td>
<td>&lt;input style="width:200px;" type="text" name="expiration_date"
id="expiration_date"/&gt;&lt;/td>
</tr>
<tr>
<td height="25"><strong>CVC2/CVV2 Code:</strong></td>
<td>&nbsp;</td>
<td>&lt;input style="width:200px;" type="text" name="cvc2_cvv2_code"
id="cvc2_cvv2_code"/&gt;&lt;/td>
</tr>
<tr><td>&nbsp;</td></tr>
&lt;form method="post"&gt;
<tr>
<td height="25" colspan="2">
</td>
<td>
&lt;!--
<img id="captcha" src="../securimage/securimage_show.php" alt="CAPTCHA
Image" height="26"/>
<a src =
'../securimage/securimage_show.php?'>[ Next
Image ]</a>
--&gt;
&lt;?php echo $cap_img ;?&gt;
<p>&lt;?php echo $cap_msg ;?&gt;</p>
</td>
</tr>
<tr>
<td height="25"><strong>Security Code:</strong></td>
<td>&nbsp;</td>
<td>&lt;input style="width:200px;" type="text" name="security_code"
id="security_code"/&gt;&lt;/td>
</tr>

<tr>
<td colspan="11">
<div id="submit-button">
<button style="height:25px; width:80px;" type="submit" name="continue">
Continue
</button>
<a href="index.php">
&lt;input style="height:25px; width:60px;" type="button"&gt;
</a>
</div>
<div class="loading_icon"></div>
</td>
</tr>
&lt;/form&gt;
</table>




Theme © iAndrew 2016 - Forum software by © MyBB