如何在当前站点上显示PHP echo HTML内容?

如何在当前站点上显示PHP echo HTML内容?,php,html,bootstrap-4,Php,Html,Bootstrap 4,是否可以在我按下按钮(键入submit)后在我的网站上显示HTML格式的echo内容,POST请求是在同一网站上发出的。 当我按下按钮时,它正在刷新网站并发出POST请求,但我不希望它自动刷新网站,如果可能,我希望在当前网站上显示警报 <button id="submit" type="submit" class="btn btn-darkred rounded mr-xl-5" style="width:300px">LOGIN</button> 登录 这是PHP代

是否可以在我按下按钮(键入submit)后在我的网站上显示HTML格式的echo内容,
POST
请求是在同一网站上发出的。 当我按下按钮时,它正在刷新网站并发出
POST
请求,但我不希望它自动刷新网站,如果可能,我希望在当前网站上显示警报

<button id="submit" type="submit" class="btn btn-darkred rounded mr-xl-5" style="width:300px">LOGIN</button>
登录
这是PHP代码

<?php

    if ($_SERVER["REQUEST_METHOD"] == "POST") {

        $secretKey = 'captchaSecret';
        $captcha = $_POST['g-recaptcha-response'];

        if(!$captcha){
        echo '<p class="alert alert-warning">Please check the the captcha form.</p>';
        exit;
        }
        $ip = $_SERVER['REMOTE_ADDR'];
        $response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);
        $responseKeys = json_decode($response,true);

        if(intval($responseKeys["success"]) !== 1) {
        echo '<p class="alert alert-warning">Please check the the captcha form.</p>';
        } else {
            echo 'successful';
        }

    }
?>

请对PHP代码进行一些更改,如我在下面提到的

<?php
  $alertMsg = "";
  if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $secretKey = 'captchaSecret';
    $captcha = $_POST['g-recaptcha-response'];
    if(!$captcha){
     $alertMsg = '<p class="alert alert-warning">Please check the the captcha form.</p>';
    } 
    else {
     $ip = $_SERVER['REMOTE_ADDR'];
     $response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);
     $responseKeys = json_decode($response,true);
     if(intval($responseKeys["success"]) !== 1) {
       $alertMsg = '<p class="alert alert-warning">Please check the the captcha form.</p>';
     } else {
      $alertMsg = '<p class="alert alert-success">successful</p>';
     }
    }
  }
?>

你的
注册是同一个站点。在这种情况下,你只需将
action=“registration”
更改为
action=“”
。我的意思是刷新页面并向我显示echo的内容,这是我的提醒,实际上,我希望我的警报显示在同一个页面上,而不是空白页面上。如果要更新页面而不刷新页面,则需要使用AJAX(通过JavaScript)。
<?php
  $alertMsg = "";
  if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $secretKey = 'captchaSecret';
    $captcha = $_POST['g-recaptcha-response'];
    if(!$captcha){
     $alertMsg = '<p class="alert alert-warning">Please check the the captcha form.</p>';
    } 
    else {
     $ip = $_SERVER['REMOTE_ADDR'];
     $response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);
     $responseKeys = json_decode($response,true);
     if(intval($responseKeys["success"]) !== 1) {
       $alertMsg = '<p class="alert alert-warning">Please check the the captcha form.</p>';
     } else {
      $alertMsg = '<p class="alert alert-success">successful</p>';
     }
    }
  }
?>