[英]How do I pass content of a text file as a url parameter
我想將文本文件的內容傳遞給url。 因此,我使用fgets函數逐行讀取文件的內容並將其存儲在字符串中,然后將其傳遞給相關的url。 但是由於某種原因,它不起作用。 如何執行此操作或將文本文件的內容作為參數傳遞給url。
$handle= fopen("/path/to/file/filename.txt","r");
while(($line=fgets($handle))!==false) {
$msisdn=str_replace("\n", " ", $line);
}
$send="http://127.0.0.1:13014/cgi-bin/sendsms?username=tester&password=foobar&text=text&from=shortcode&to=$msisdn&smsc=smsc";
fclose($handle);
$curl=curl_init();
curl_setopt($curl,CURLOPT_URL,$send);
curl_setopt($curl,CURLOPT_RETURNTRANSFER, 1);
$result=curl_exec($curl);
curl_close($curl)
編輯:我能夠將文件的內容(這是數字的列表)傳遞給字符串“ $ msisdn”,但是URL的回顯顯示它僅選擇一個數字。 我如何將文件的所有內容傳遞給url。
$handle= fopen("/path/to/file/filename.txt","r");
while(($line=fgets($handle))!==false){
$msisdn=str_replace("\n", " ", $line);
}
$send="http://127.0.0.1:13014/cgi-bin/sendsms?username=tester&password=foobar&text=text&from=$shortcode.&to=$msisdn&smsc=smsc";
fclose($handle);
header('Location: '.$send);
1 :永遠不要在URL中傳輸機密數據=>安全問題
第二 :始終驗證函數的返回值=>您不能保證文件已成功打開
第三 :文件的結構是什么? 我們應該猜嗎?
第四 :嘗試使用類似這樣的方法實現更好的實現
$params = array ('username' => $username,
'text' => $text);
$preparedParams = array();
foreach($params as $paramKey => $paramValue) {
// do control if $paramValue is valid ... log error .. throw something
$preparedParams[] = $paramKey . '=' . $paramValue ;
}
$urlParams = explode ('&', $preparedParams);
header('Location: ' . YOUR_SERVER:PORT/YOUR_CONTROLLER/ . $urlParams;
我的建議是使用PHP CURL代替header('Location: ')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.