2016-03-06 54 views
0

我有一个网站接收一些参数并返回一个电话号码。带var参数的PHP file_get_contents失败

这是呼叫我从其他页面做:

$phoneNumber= file_get_contents("https://page.company.test/?app=$appid&affiliateid=$affiliatep&laNG=en&country=$countryp&sav=$savactive"); 

失败网址传递这样。我回应了整个网址,并设置了正确的变量。

但是,如果使用的URL这样的,它的工作原理:

file_get_contents("https://page.company.test/?app=tsc&affiliateid=main&laNG=en&country=au&sav=false"); 

我怎么错过?

+0

你有没有https(与http)尝试? (file_get_contents(“http://tfnlicense.safebytes.com/?app=tsc&affiliateid=main&laNG=en&country=au&sav=false”);) – Vigikaran

回答

0

您不传递变量,但现在使用字符串。

尝试拓展变量和串联串

$phoneNumber= file_get_contents("https://page.company.test/?app=".$appid."&affiliateid=".$affiliatep."&laNG=en&country=".$countryp."&sav=".$savactive) 

查看更多方便易方式在阵列中的所有选项:GET Request from PHP using file_get_contents with parameters

+0

不适用于我:(:$ phoneNumber = file_get_contents(“https:// page .company.test /?app =“。$ appid。”&affiliateid =“。$ affiliatep。”&laNG = en&country =“。$ countryp。”&sav =“。$ savactive); –

0

(PHP 4,PHP 5,PHP 7)用urlencode - URL-编码字符串

字符串进行urlencode($字符串STR)

这个功能很方便当 编码在URL的查询部分中使用的字符串时,作为便捷的 方式将变量传递到下一页。

尝试编码您的网址以传入file_get_contents()函数。

$url = "https://page.company.test/?app=$appid&affiliateid=$affiliatep&laNG=en&country=$countryp&sav=$savactive"; 
$url = urlencode($url); 
$phoneNumber = file_get_contents($url); 

请参见PHP文档的详细信息:http://php.net/manual/en/function.urlencode.php

+0

试过这个Fin Fin $ url = ?HTTPS://page.company.test/应用= $的appid&AFFILIATEID = $ affiliatep&LANG = EN&国家= $ countryp&SAV = $ savactive“; $ URL =用urlencode($网址); $ phoneNumber的=的file_get_contents($网址); 但我没有收到任何东西,而我回应了我看到的这个$ url:https%3A%2F%2Ftfnlicense.safebytes.com%2F%3Fapp%3Dtsc%26affiliateid%3D%26laNG%3Den%26country%3Dus%26sav%3Dfalse –

+0

The link你提供的并不会给我的浏览器带来任何结果,那么链接应该是什么呢? – Fin

0

想通了,感谢您的帮助,另一边的开发做出强制要求使用AFFILIATEID参数,他只是ping通我用“主要”。同样使用这一伟大工程$ phoneNumber的=的file_get_contents( “https://page.company.test/?app=”。$ APPID。 “& AFFILIATEID =主”。$ affiliatep。 “& LANG = EN &国家=” $ countryp。 “& SAV =” $ savactive );