2016-03-06 53 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 );