消息系統使用相同的功能發送和回覆消息。一個用戶發送消息給另一個主題:「只測試69英鎊100美元@公頃」。並且消息包含文本,php和html。 PHP被CI xss_clean剝離,html被系統阻塞/取代。它發送沒有錯誤。其他用戶收到它,打開它並嘗試用47個字符的純文本回復。 CI表單驗證類將其封鎖並顯示錯誤:主題必須少於1000個字符。第一個也是最重要的問題是它不應該引發驗證錯誤。其次CI形式val。已將主題設置爲最大。 30個字符,並將消息設置爲最多1000個字符 - 因此錯誤消息也不正確。我的直覺是,這個主題中的一個角色正在打亂CI形式val。但是當原始信息被髮送時它並沒有讓它感到不安!任何想法這裏發生了什麼?Codeigniter驗證問題
以下是表單中的相關代碼;
<form name="sendmessage" method="POST" action="<? echo base_url(); ?>user/messaging/sendmessage/">
<input type="hidden" name="<?php echo $this->security->get_csrf_token_name(); ?>" value="<?php echo $this->security->get_csrf_hash(); ?>" />
<input type="hidden" name="recipiant" value="<? echo $message['mem_msg_from_id']; ?>" />
<input type="hidden" name="thread" value="<? echo $message['mem_msg_thread_id']; ?>" />
<? if(substr($message['mem_msg_subject'],3) == 'Re:'){$subject = $message['mem_msg_subject'];}else{$subject = 'Re: ' . $message['mem_msg_subject'];} ?>
<input type="hidden" name="subject" value="<? echo ucfirst($subject); ?>">
這裏是控制器代碼;
public function sendmessage(){
if($this->input->is_ajax_request()){ // ajax request only
$subject = $this->input->post('subject',TRUE);
$message = $this->input->post('message',TRUE);
$recipiant = $this->input->post('recipiant',TRUE);
$thread_id = $this->input->post('thread',TRUE);
$subject_val = $this->form_validation->set_rules('subject', 'Subject', 'required|min_length[3]|max_length[30]');
$subject_req_error = $this->form_validation->set_message('required', 'A %s is required!');
$subject_min_error = $this->form_validation->set_message('min_length', '%s must be at least 3 characters!');
$subject_max_error = $this->form_validation->set_message('max_length', '%s must be under 30 characters!');
$message_val = $this->form_validation->set_rules('message', 'Message', 'required|min_length[5]|max_length[1000]');
$message_req_error = $this->form_validation->set_message('required', 'A %s is required!');
$message_min_error = $this->form_validation->set_message('min_length', '%s must be at least 5 characters!');
$message_max_error = $this->form_validation->set_message('max_length', '%s must be under 1000 characters!');
$this->form_validation->set_error_delimiters('<div class="pull-left">',' </div><br>');
if ($this->form_validation->run() == FALSE){ // FAILED TRY AGAIN
echo '<div style="font-weight: bold; color: red;">' . form_error('subject') . form_error('message') . '</div>';
}else{ // ALL SEEMS TO BE IN ORDER HERE
// clean it up a bit
$subject = str_replace('<', '', $subject);
$subject = str_replace('>', '' , $subject);
$subject = auto_link($subject, 'both', TRUE);
$message = str_replace('<', '', $message);
$message = str_replace('>', '' , $message);
$message = auto_link($message, 'both', TRUE);
// stick it in the database
$db = $this->user_messaging_model->sendMessage($this->userinfo['user_id'], $recipiant, $subject, $message, $thread_id);
echo 'sent';
}
}
}
你有沒有加載表單助手? – sandip 2013-03-06 04:26:20
@sandip是的,如果我沒有,它會拋出一個錯誤。 – Ally 2013-03-06 16:42:50