在第三方URL重定向后,如何在php中进行响应



如何在第三方URL重定向php的情况下获得响应?

function curlRequest($url) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
    curl_setopt($ch, CURLOPT_URL, $url); 
    $result = curl_exec($ch); 
    return $result; 
}

curl_test_redirect.php

<?php
function curlRequest($url) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
    $result = curl_exec($ch); 
    return $result; 
}
echo curlRequest('http://localhost//myWork/testPHP/curl_first_hit.php');
?>

curl_first_hit.php

<?php
echo 'hello in first hit';
header('Location: http://localhost//myWork/testPHP/curl_second_hit.php');
?>

curl_second_hit.php

<?php
echo 'hello in second hit';
?>

最新更新