Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Following is the call to an URL using CURL :

<?php
    ini_set('display_startup_errors',1);
    ini_set('display_errors',1);
    error_reporting(-1);

    $link = $_GET['link'];
    $url  = "http://www.complexknot.com/user/verify/link_".$link."/";


    // create a new cURL resource
    $ch = curl_init();

    // set URL and other appropriate options
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, 0);

    // grab URL and pass it to the browser
    curl_exec($ch);

    // close cURL resource, and free up system resources
    curl_close($ch);
?>

The variable $url contains one URL which I'm hitting using CURL.

The logic written in the file(present in a variable $url) is working absolutely fine.

After executing the code I want the control to be redirected to one URL. For it I've written following code :

header('Location: http://www.complexknot.com/login.php');
exit; 

The following code is not working. The URL http://www.complexknot.com/login.php is not opening and a blank white page appears. This is the issue I'm facing.

If I don't use the CURL and hit the URL i.e. the URL contained in $url then it gets redirect to the URL http://www.complexknot.com/login.php that means header function works fine when I hit the URL in browser.

Why it's not working when I call it from CURL?

Please someone help me.

Thanks in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
177 views
Welcome To Ask or Share your Answers For Others

1 Answer

This is happening because CURL is outputting the data. You must use curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); in order to let CURL returning data instead of outputting it.

<?php
ini_set('display_startup_errors', 0);
ini_set('display_errors', 0);
error_reporting(0);

$link = $_GET['link'];
$url  = "http://www.complexknot.com/user/verify/link_$link/";

// create a new cURL resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 

// grab URL and pass it to the browser
curl_exec($ch);

// close cURL resource, and free up system resources
curl_close($ch);

header('Location: http://www.complexknot.com/login.php');

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...