我正在尝试生成一个XML文件,但是这个file_get_contents()
PHP函数出现错误,这是我的代码:
function mobile_login1($P1, $P2)
{
$url = 'myURL';
$data = array(
'username' => $P1,
'password' => $P2);
// use key 'http' even if you send the request to https://...
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded",
'method' => 'POST',
'content' => http_build_query($data),
),
);
$context = stream_context_create($options);
$json_data = file_get_contents($url, false, $context);
$decode = json_decode($json_data);
//print_r ($decode[0]);
//
foreach($decode as $row)
{
$data[] = array("Message" => $row->msg);
}
//print_r ($data[0]['Message']);
$msg = $data[0]['Message'];
if ($msg == 'Incorrect username/password')
{
$this->response['ResponseCode'] = "1000";
$this->response['ResponseMessage'] = $msg;
$this->response['ResponseData'] = $data;
}
else
{
if($decode != null)
{
foreach($decode as $row)
{
$data[] = array("AccountId" => $row->a_id,
"PersonalId" => $row->p_id,
"FullName" => $row->full_name,
"AccountName" => $row->a_name,
"AccountType" => $row->a_type,
"WalletBalance" => $row->wallet_balance,
"PersonalAddress" => $row->p_add,
"CompanyName" => $row->company_name,
"CompanyAddress" => $row->company_add,
"Fax" => $row->fax,
"PersonalMobile" => $row->p_mobile,
"PersonalTelephone" => $row->p_tel,
"Limit" => $row->limit,
"Role" => $row->role,
"AccountMobile" => $row->a_telno);
}
$this->response['ResponseCode'] = "0000";
$this->response['ResponseMessage'] = "successful";
$this->response['ResponseData'] = $data;
}
else
{
$this->response['ResponseCode'] = "1000";
$this->response['ResponseMessage'] = "no records found";
}
}
//return $json_data;
}
当我尝试调用我的网址错误时,行号187
是我的 file_get_contents()功能的代码。
A PHP Error was encountered Severity: Warning Message:
file_get_contents(http://myURL/mobile_login): failed to open stream: Permission denied
Filename: models/accounts_model.php Line Number: 187
此服务器是错误还是PHP错误?
答案 0 :(得分:14)
事实证明这是我服务器上的一个问题:
我从终端跑了这条线来重新载入它
setsebool -P httpd_can_network_connect on
感谢你们的建议
答案 1 :(得分:3)
我有同样的问题,如上所述,以下在Centos 7上为我工作
setsebool -P httpd_can_network_connect on
答案 2 :(得分:1)
我在使用LAMP + Wordpress的自配置CentOS6主机上遇到了同样的问题。 Wordpress wp_remote_get()函数没有返回结果(并且没有返回错误),也没有返回PHP file_get_contents()。在主机上执行此操作解决了这个问题。
setsebool -P httpd_can_network_connect on