首页 > 解决方案 > 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);
    }
?>

我会很感激任何帮助。

标签: phpprestashoprecaptcha

解决方案


推荐阅读