php - PrestaShop 1.5 添加 PHP (reCaptcha)
问题描述
目前我正在处理版本 1.5 中过时的 PrestaShop 实例。需要集成 Google 的 reCaptcha。到目前为止,这很容易。除了响应代码,它是一个 PHP 脚本,还不能工作。有没有一种简单的方法可以将 PHP 代码集成到这样的 PrestaShop 中?它必须在 HTML 代码之前加载。
主要问题是,我不知道如何在 PrestaShop 1.5 中实现 PHP 代码。没有任何教程或文档了。大多数提示都是针对 CMS 页面中的代码的,但我需要它在头顶。
我要实现的代码如下所示:
<?php
if(isset($_POST['submitMessage'])){
$url = "https://www.google.com/recaptcha/api/siteverify";
$data = [
'secret' => "***",
'response' => $_POST['token']
];
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);
echo "<pre>";
print_r($response);
}
?>
我会很感激任何帮助。
解决方案
推荐阅读
- forms - 在对话框中使用 FluentValidation 和 MudBlazor 进行表单验证
- python - tensorflow2中的model(input)和model.predict(input)有什么区别?
- symfony - Symfony 根据条件验证对象
- flutter - dart : 使用任何一个来处理 api 失败
- xslt-3.0 - 使用 xslt-3 将 xml 元素合并到一个元素中
- javascript - 是否可以在 html 中预加载二进制文件?
- data-visualization - 如何指定 x 范围以查看密度图?
- javascript - 我想从 api 报价中获取数据
- encryption - 使用 Libsodium 和 SSL (HTTPS) 时的 Apple 出口合规性
- node.js - 我想在未来的日期/时间运行一个函数 - 一次 | nodejs - 后端任务?