Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/237.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在成功重述TCHA后自动重定向到页面(我不熟悉编码)_Php_Http_Redirect - Fatal编程技术网

Php 如何在成功重述TCHA后自动重定向到页面(我不熟悉编码)

Php 如何在成功重述TCHA后自动重定向到页面(我不熟悉编码),php,http,redirect,Php,Http,Redirect,我正在尝试在ReCaptcha成功后自动将用户重定向到 <?php require('src/autoload.php'); $siteKey = 'my-site-key'; $secret = 'my-secret-key'; $recaptcha = new \ReCaptcha\ReCaptcha($secret); $gRecaptchaResponse = $_POST['g-recaptcha-response']; //google captcha post data

我正在尝试在ReCaptcha成功后自动将用户重定向到

<?php
require('src/autoload.php');

$siteKey = 'my-site-key';
$secret = 'my-secret-key';

$recaptcha = new \ReCaptcha\ReCaptcha($secret);

$gRecaptchaResponse = $_POST['g-recaptcha-response']; //google captcha post data
$remoteIp = $_SERVER['REMOTE_ADDR']; //to get user's ip

$recaptchaErrors = ''; // blank varible to store error

$resp = $recaptcha->verify($gRecaptchaResponse, $remoteIp); //method to verify captcha
if ($resp->isSuccess()){
    header('Location: http://www.theurl.com/');  //this is where it should redirect to
    exit;
} 
else {
   $recaptchaErrors = $resp->getErrorCodes(); // set the error in varible
}
?>

标题('位置:http://www.theurl.com/');是正确的。你还没有详细描述你的问题。具体是什么出了问题?你做了什么调试?一些调试提示:如果它没有重定向你,那么a)你检查过代码是否真的进入了
If($resp->issucess()){
块吗?b)你检查过返回到浏览器的响应,看它是否真的包含位置头吗?(实际执行重定向的是浏览器——PHP只是设置了一个HTTP响应头,告诉它这样做。)c)您不是通过AJAX运行的,是吗?因为AJAX客户机不会接受重定向请求(因为这样做违背了AJAX的主要目的)。谢谢@ADyson!对不起。问题是我想-如果成功勾选了ReCaptcha,请重定向页面。我是新手,所以我不知道如何检查代码是否进入if($resp->issucess()){block.我正在使用标准的ReCapcha代码…我在哪里可以看到它是否是AJAX?对于所有愚蠢的问题,我很抱歉…仍然在这里学习进行快速调试的最简单方法是使用命令。这可以让您查看变量的值,或者只输出一些文本,以便您知道代码已经到达某个位置。因此,在您的测试中,如果($resp->issucess()){var_dump(“success”);//header('Location:http://www.theurl.com/“);//这是它应该重定向到退出的地方;}否则{var_dump(“fail”);$recaptchaErrors=$resp->getErrorCodes();//在变量中设置错误}
如果代码进入if块或else块,则应在屏幕上显示