【发布时间】:2019-12-21 04:48:23
【问题描述】:
我正在将 CURL 查询从我的测试文件(以模仿将来来自另一个服务的 POST 请求)发送到我的工作文件。问题是我在收到 POST 请求后尝试重定向用户,但没有运气,既不是通过 JS 也不是通过 PHP。也许您可以看一下并告诉我错误在哪里,因为调试器或控制台或网络选项卡中没有错误?即 session_id - 会话在 User 类中开始,所以它工作正常。提前致谢
主文件代码:
require_once('../../api/classes/User.php');
header('Access-Control-Allow-Origin: *');
$user = new User();
if(isset($_POST['user_id']) && isset($_POST['game']) && isset($_POST['level'])){
// echo "<script type='text/javascript'> window.location = '../pages/Games/".$_POST['game']."/game.php?token=".session_id()."&level=".$_POST['level'] . "</script>";
header("Location: someurl/pages/Games/".$_POST['game']."/game.php?token=".session_id()."&level=".$_POST['level']);
}
?>
测试文件:
<?php
$ch = curl_init();
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
$params = array(
// "creditBalance"=>"4900",
// "level"=>1,
// "result"=>10,
"user_id"=>"3974ac1f-ec60-c3ea-586e-e822fed8d326",
"map"=>"",
"game" => "PetroPro",
"level" => "2"
// "token"=>"u39ukhtcjffg86rdj8i011jd82"
);
curl_setopt($ch,CURLOPT_URL,"http://localhost/someurl/startSingleGame.php");
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,http_build_query($params));
$result = curl_exec($ch);
curl_close($ch);
?>
我希望在 test.php 发送请求之后,URL 应该从 test.php 更改为我在标头中发送的任何内容。
【问题讨论】:
-
PHP 不会在任何选项卡上的检查元素窗口中显示错误。这是为客户端错误/日志保留的
-
这和 JS 有什么关系? o.O
-
另外,
header('Location ..')后面应该跟exit() -
@GrumpyCrouton 我正在为 Visual Studio 使用 xDebug,它通常会显示标题是否有问题
-
@msg 看到了,试过了,没用 =(
标签: javascript php curl