|
 |
|
การใช้งาน captcha มีปัญหาเวลาเช็ค time()-7200 , php-codeigniter |
|
 |
|
|
 |
 |
|
Code (PHP)
# function floor(); ปัดทศนิยมออก
$this->captcha->_insert( floor($captcha['time']), $this->input->ip_address(), $captcha['word'] );
$checking = $this->db->where(.....)->get(....)->row_array();
if ( time() > $checking['time'] ) {
# error
}
ปกติผมใช้ Session จำเอาอ่าคับ.. แหะๆ
|
 |
 |
 |
 |
Date :
2014-09-02 17:18:16 |
By :
parsilver |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ทำไม captcha['time']
กับ
time()-7200
มันได้ค่าตัวเลขไม่ตรงกันล่ะครับ? แล้วจะตรวจสอบอย่างไรครับ?
* captcha['time'] มีค่า default expiration => 7200
ขอบคุณทุกคำตอบครับ
ขออนุญาตพื้นที่ไทยครีเอทครับ
|
 |
 |
 |
 |
Date :
2014-09-02 22:56:44 |
By :
ginuwine72 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองเปลี่ยนจาก
-7200
เป็น
-(60*60*24)
มันช่วยได้ครับ
แต่..! ก็ยังหาสาเหตุไม่เจอ ว่าเป็นเพราะอะไร
ขอบคุณ oOPAOo
ขอบคุณพื้นที่ไทยครีเอทครับ
|
 |
 |
 |
 |
Date :
2014-09-07 19:33:11 |
By :
ginuwine72 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมใช้แบบนี้
Code (PHP)
$vals = array(
'word' => rand_captcha(6),
'img_path' => './captcha/',
'img_url' => 'http://localhost/apps/captcha/',
'font_path' => './assets/fonts/chunkfive-webfont.ttf',
'img_width' => '150',
'img_height' => 40,
'expiration' => 900
);
$captcha = create_captcha($vals);
$this->session->set_userdata('captchaWord', $captcha['word']);
$data['captcha']=$captcha['image'];
$this->load->view('captcha-view', $data);
'expiration' => 900
กำหนด expire ที่นี่ได้เลยเพื่อลบไฟล์รูปที่ Gen ออกมา
ส่วนตอน Veriry ก็
Code (PHP)
public function verify()
{
$this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<p class="error">', '</p>');
$this->form_validation->set_rules('details', "Description", 'trim|required|xss_clean');
$this->form_validation->set_rules('captcha', "Captcha", 'trim|required|callback_captcha_check');
$userCaptcha = set_value('captcha');
$word = $this->session->userdata('captchaWord');
if($this->form_validation->run() == FALSE)
{
$this->test();
}
else
{
$this->session->unset_userdata('captchaWord');
$data = array(
'details' => $this->input->post('details', TRUE),
'active' => 'Y',
'ip' => $this->input->ip_address(),
'create_by' => $this->sess['username']
);
$this->db->trans_begin();
$this->db->set('created', 'NOW()', FALSE);
$this->db->insert('mytable', $data);
if ($this->db->trans_status() === FALSE)
{
$this->db->trans_rollback();
$msg=notification('error', $this->db->last_query());
}
else
{
$this->db->trans_commit();
$msg=notification('success', 'Insert Record has been successfully. # '.$this->db->affected_rows().' effected.');
}
$this->session->set_flashdata('message', $msg);
redirect('captcha/index');
}
}
function captcha_check()
{
if($this->input->post('captcha') != $this->session->userdata('captchaWord'))
{
$this->form_validation->set_message('captcha_check', 'Wrong captcha code!');
return false;
}
return true;
}
|
 |
 |
 |
 |
Date :
2014-09-08 13:44:14 |
By :
fossil31 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|