【发布时间】:2017-07-12 15:57:53
【问题描述】:
我是 PHP 和 Laravel 的新手,我有以下奇怪的问题。
我开发了一个包含 Google reCAPTCHA 字段的注册表单,如下所示:
<form method="post" action="/registration">
...............................................................
...............................................................
...............................................................
<div class="form-group">
<label>Captcha</label>
<div class="input-group">
{!! app('captcha')->display(); !!}
</div>
</div>
{{csrf_field()}}
<button type="submit" class="btn btn-default">Submit</button>
</form>
因此,该字段包含经典的“我不是机器人”复选框。
如果我只需要选中此复选框,那么在将表单提交给处理 /registration 资源的控制器时我没有问题。
这是处理此请求并验证表单输入的控制器方法(带有相关的输入表单验证器):
public function store(Request $request) {
Log::info('store() START');
$data = Input::all();
Log::info('INSERTED DATA: '.implode("|", $data));
$rules = array(
'name' => 'required',
'surname' => 'required',
'login' => 'required',
'email' => 'required|email|confirmed',
//'email_confirmation' => 'required|email|confirmed',
'pass' => 'required|required',
//'passConfirm' => 'required',
'g-recaptcha-response' => 'required|captcha',
);
$validator = Validator::make($data, $rules);
if ($validator->fails()){
return Redirect::to('/registration')->withInput()->withErrors($validator);
}
else{
// Do your stuff.
}
}
如果打开弹出窗口要求选择一些特定的图像,当我提交表单时,我会收到以下错误消息:
RequestException in CurlFactory.php line 187:
cURL error 60: SSL certificate problem: unable to get local issuer certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
in CurlFactory.php line 187
at CurlFactory::createRejection(object(EasyHandle), array('errno' => 60, 'error' => 'SSL certificate problem: unable to get local issuer certificate', 'url' => 'https://www.google.com/recaptcha/api/siteverify', 'content_type' => null, 'http_code' => 0, 'header_size' => 0, 'request_size' => 0, 'filetime' => -1, 'ssl_verify_result' => 20, 'redirect_count' => 0, 'total_time' => 0.079000000000000001, 'namelookup_time' => 0.016, 'connect_time' => 0.032000000000000001, 'pretransfer_time' => 0, 'size_upload' => 0, 'size_download' => 0, 'speed_download' => 0, 'speed_upload' => 0, 'download_content_length' => -1, 'upload_content_length' => -1, 'starttransfer_time' => 0, 'redirect_time' => 0, 'redirect_url' => '', 'primary_ip' => '216.58.212.132', 'certinfo' => array(), 'primary_port' => 443, 'local_ip' => '168.202.22.52', 'local_port' => 50542)) in CurlFactory.php line 150
进入之前的store(Request $request)控制器方法。我认为问题与此验证设置有关:
'g-recaptcha-response' => 'required|captcha'
因为我认为它会自动调用 Google 服务器来检查验证码(事实上,在之前的错误消息中,它指定了这个应该与 Google 相关的 IP:216.58.212.132)。
所以,在网上搜索我发现与这种错误有关的类似内容:
基本上是说一个 cacert.pem 文件,该文件必须设置到 Apache 中。
它是这样的:
我有完全相同的,但在 Windows 和 xampp 上。我的解决方案很简单 如:点击此链接:http://curl.haxx.se/ca/cacert.pem 复制 整个页面并将其保存在:“cacert.pem”
然后在您的 php.ini 文件中插入或编辑以下行: curl.cainfo = "[pathtothisfile]\cacert.pem"
问题解决了
据我所知,这个文件 (https://curl.haxx.se/ca/cacert-2017-01-18.pem) 是一组 CA 证书,您可以使用它来验证服务器是否确实是您正在与之交谈的正确站点。
所以我没有将此文件设置到我的 Apache 中的事实可能是我的问题的原因?
如果是,我该怎么做才能设置它?我不明白我与这个下载的文件有什么关系。
【问题讨论】:
标签: php laravel ssl laravel-5 recaptcha