2015-10-14 27 views
-1

以下是调用使用curl的网址:为什么在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); 
?> 

变量$url包含了我使用curl打一个网址。

写入的文件(存在于可变$url)中的逻辑工作精绝。

执行的代码后,我想控制被重定向到一个URL。对此我写了以下代码:

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

以下代码无法正常工作。网址http://www.complexknot.com/login.php未打开并出现空白页面。这是我面临的问题。

如果我不使用卷曲和打URL即包含在$url的网址,然后它被重定向到,这意味着头功能正常工作时,我打的网址在浏览器的URL http://www.complexknot.com/login.php

为什么它不工作时,我把它从卷曲?

请别人帮我。

在此先感谢。

回答

0

这是发生,因为卷曲输出数据。您必须使用curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);才能让CURL返回数据而不是输出数据。

<?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'); 
+0

谢谢您的回答。你能告诉我,我应该在哪里添加这一行或更好的请你张贴我的完整代码,添加新行作为答案,以便我可以接受你的答案? – PHPLover

+0

我刚更新了我的答案.. –

+0

对不起,但问题仍然存在。 – PHPLover

0

您可以使用

<?php echo "<script>window.location.href = 'http://www.complexknot.com/login.php';</script>";die; ?>

相关问题