【发布时间】:2018-12-12 10:34:11
【问题描述】:
我正在使用 Codeigniter 3.1.9 并在本地计算机上完成了我的表单。我刚刚在服务器上上传了我的应用程序并收到错误
无法访问与您的字段名称对应的错误消息 网址。(有效网址格式)
我google了很多,但无法解决问题。
文件名:My_Form_validation.php 位置:应用程序\库
class MY_Form_validation extends CI_Form_validation{
public function __construct()
{
parent::__construct();
}
function valid_url_format($str){
$pattern = "/^(http|https|ftp):\/\/([A-Z0-9][A-Z0-9_-]*(?:\.[A-Z0-9][A-Z0-9_-]*)+):?(\d+)?\/?/i";
if (!preg_match($pattern, $str)){
$this->set_message('valid_url_format', 'The URL you entered is not correctly formatted.');
return FALSE;
}
return TRUE;
}
function url_exists($url){
$url_data = parse_url($url); // scheme, host, port, path, query
if(!fsockopen($url_data['host'], isset($url_data['port']) ? $url_data['port'] : 80)){
$this->set_message('url_exists', 'The URL you entered is not accessible.');
return FALSE;
}
return TRUE;
}
}
文件名:UrlChecker.php 位置:应用程序\控制器
class UrlChecker extends CI_Controller {
public function __construct() {
parent::__construct();
}
public function _initializing(){
}
public function index()
{
$this->form_validation->set_rules('link', 'URL', 'required|trim|valid_url_format|url_exists');
if ($this->form_validation->run() == FALSE)
{
echo validation_errors('<div class="alert alert-danger" role="alert">', '</div>');
}
else
{
echo 'ok';
}
}
请检查并让我知道是托管版本问题还是其他问题。
【问题讨论】:
标签: codeigniter