2012-07-20 40 views
0

我的问题是下面,我有一个EmailReports.php我的服务器上,我用它来发送类似[email protected] &邮件内容= 123456.pdf如何从PHP调用网站服务?

我不能修改EmailReports .php,因为它属于一个不同的项目,它立即发送一封电子邮件,并被质量保证团队和所有这些东西所推动。

现在,在一个不同的LookReports.php我需要提供一个服务,如“给我发送我回顾的报告”,手动可以很容易地执行,就像调用EmailReports.php一样,问题是,我该如何做PHP代码?所以它会自动调用其他PHP。

我曾尝试没有成功:

$stuff = http_get("http://...<the url here>"); 

$stuff = file_get_contents("http://...<the url here>"); 

我想进口的EmailReports.php但看起来不正确,因为没有的功能,它会自动发送一封电子邮件。

或者我可以复制EmailReports.php代码,但这是违反质量保证政策,因为需要额外的测试。

你能指导我一下吗?

在此先感谢。

+1

使用file_get_contents时是否出现错误?什么是返回$东西?那将是从PHP脚本中调用外部URL的正确方法? – 2012-07-20 04:05:05

+0

'file_get_contents'应该可以用于简单的GET调用。 – 2012-07-20 04:06:35

+0

@AaronDougherty Thx回复,没有错误,和$东西是空的。 – nxgtrturbo 2012-07-20 04:08:39

回答

5

您可以使用Curl请求从任何网站检索信息(xml/html/json/etc)。

什么是CURL? (简短回答)

PHP有一个非常强大的调用库,专门用于安全地从远程站点获取数据。它被称为CURL。

来源:卷曲功能的PHP PHP, CURL, and YOU!

/* gets the data from a URL */ 
function get_data($url) 
{ 
if(function_exists('curl_init')){ 
$ch = curl_init(); 
$timeout = 5; 
curl_setopt($ch,CURLOPT_URL,$url); 
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); 
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout); 
$data = curl_exec($ch); 
curl_close($ch); 
return $data; 
} else 'curl is not available, please install'; 
} 

来源:Download a URL’s Content Using PHP cURL

或者,你可以做你正在与file_get_contents做什么,但许多主机不允许这样做。 (沃尔什,2007)

使用

<?php 
$mydata = get_data('http://www.google.co.nz'); 
echo '<pre>'; 
print_r($mydata); //display the contents in $mydata as preformatted text 
echo '</pre>'; 
?> 

尝试测试它,与其他网站,因为往往不是google将返回404 request(这是可以预料的),经过卷曲已执行。

+0

这也不行,我认为它可能与服务器配置有关? – nxgtrturbo 2012-07-20 04:15:07

+0

curl现在默认使用'PHP 5.4.3' [curl requirements](http://www.php.net/manual/en/curl.requirements.php),或者如果你正在运行类似windows的东西系统与'xammp'安装我会看看这个问题[这里](http://stackoverflow.com/questions/181082/how-do-i-install-curl-on-windows)。问候 – Killrawr 2012-07-20 04:19:25

+0

我正在使用PHP 5.2.17的远程Linux服务器,这可能是原因不起作用,但我会期望至少有一个错误。 – nxgtrturbo 2012-07-20 04:23:28

相关问题