简体   繁体   中英

How to get response after third party url redirection in PHP with curl

How to get response after third party url redirection in PHP with curl?

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';
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM