2015-09-24 79 views
-4

我有下面的PHP代码:PHP代码返回布尔(假)

<?php 

$ch = curl_init(); 

$url = "http://api/url/mac_address"; 

curl_setopt($ch, CURLOPT_URL,$url); 

curl_setopt($ch, CURLOPT_POST, true); 

curl_setopt($ch, CURLOPT_POSTFIELDS, "msg=TEST"); 

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 

$output = curl_exec ($ch); 

curl_close ($ch); 

var_dump($output); 

?> 

它是一台服务器上正常工作,但是当我在其他服务器上运行它,它会返回布尔(假)。

+0

添加代码,请 – besciualex

+0

+0

一台服务器可以达到的URL地址,另一台不能。就如此容易。 –

回答

0

使用下面的代码调试:

if(curl_exec($ch) === false) 
{ 
    echo 'Curl error: ' . curl_error($ch); 
} 
else 
{ 
    echo 'Operation completed without any errors'; 
} 

来源:http://php.net/manual/en/function.curl-error.php

+0

这可以帮助我。考虑到我的2台服务器位于不同的位置,解决域问题有一个问题,这就是为什么代码只能在一个服务器上工作,而另一个则不是。 TNX –