为了账号安全,请及时绑定邮箱和手机立即绑定

cURL 重定向返回的 URL

cURL 重定向返回的 URL

PHP
慕码人8056858 2022-12-03 10:58:39
我想将数据从站点 A 发送到站点 B。我已成功传输数据,但我想将 url 重定向到从 Curl 生成的返回 url。下面是我的代码。$jsonData = array('first_name' => "$fname",'last_name' => "$lname",'phone_number' => "$phone",'gender' => "$gender",'email' => "$email",'businessname' => "$businessname",'natureofbusiness' => "$biznature", 'address' => "$address", 'utm' => "esg", 'date' => "$d");$jsonDataEncoded = json_encode($jsonData);curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); $result = curl_exec($ch);这是结果{"data":{"success":true,"redirectUrl":"https://url.com/authorize/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1ODU5MDg4MzgsImRhdGEiOnsidXRtIjoiZXNnIiwiZW1haWwiOiJjbm5lYnVlNGFsbEB5YWhvby5jb20iLCJmaXJzdE5hbWUiOiJDaGltYSIsImxhc3ROYW1lIjoiT3NjYXIiLCJjb250YWN0TnVtYmVyIjoiOTg3MzczNjM3MyIsInRpbWVTdGFtcCI6IjE1ODU5MDc4NTUifSwiaWF0IjoxNTg1OTA4NTM4fQ.v6ecH7Tu5WB0ZkK-U2ob_sQRSNn13rOU95Zo4BgwSF4?utm=esg","status":200}}我需要帮助才能重定向到该网址。
查看完整描述

1 回答

?
不负相思意

TA贡献1777条经验 获得超10个赞

将 JSON 结果转换为数组


$result = '{"data":{"success":true,"redirectUrl":"https://url.com/authorize/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1ODU5MDg4MzgsImRhdGEiOnsidXRtIjoiZXNnIiwiZW1haWwiOiJjbm5lYnVlNGFsbEB5YWhvby5jb20iLCJmaXJzdE5hbWUiOiJDaGltYSIsImxhc3ROYW1lIjoiT3NjYXIiLCJjb250YWN0TnVtYmVyIjoiOTg3MzczNjM3MyIsInRpbWVTdGFtcCI6IjE1ODU5MDc4NTUifSwiaWF0IjoxNTg1OTA4NTM4fQ.v6ecH7Tu5WB0ZkK-U2ob_sQRSNn13rOU95Zo4BgwSF4?utm=esg","status":200}}';

$result = json_decode($result, true);


现在从数组中获取 url。


if(isset($result["data"])){

        if($result["data"]["success"]==true){

            $url  = $result["data"]["redirectUrl"];

            header("location:".$url);

        }

    }


查看完整回答
反对 回复 2022-12-03
  • 1 回答
  • 0 关注
  • 135 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信